How to connect multiple database in mongodb/node js using mongoose

preview_player
Показать описание
Here I show you how to connect multiple mongodb instances in node js using mongoose ,if you have any doubts or clarifications comment below
Рекомендации по теме
Комментарии
Автор

How do you reference the db1 and db2 if the Models and routes are defined in different files? Lmk If i can clarify my question better.

RazzNBlue
Автор

Can you still reference other objects that are in different DB's?

ex:
Name: {name: String}
Email: {email: String, user_id: { type: Schema.Types.ObjectId, ref: 'Name'}}

spreadItWide
Автор

Could you please post the code itself in the description(or upload it in a link)? It should take just a moment and would help me a lot.

IurySantos-npvs
Автор

I tried this method of your to create connection successfully. However, I got an issue that is when the first time the app initiate connections, if somehow the internet get disconnected or link to database is down(database is not local), therefore the app fail to initiate the instance so that the whole app crash because it can not use the .model() of failed connection. If anyone has any idea or work around about this problem, please let me know.

sonnguyendang