Search code examples
mongodbcollectionsormdatabase-connection

How to connect to a collection in mongodb


I want to use the collections as DBs! That is, make a connection from node.js where you can use a collection as a normal database?

The purpose of this is that I'm going to create two totally different apps, with different collections and documents, but there are data that I need to relate between the two apps. And if the two apps are using the same database, it would be much easier for me.


Solution

  • Well.. MongoDB doesnt do that, what can you do is something like give a prefix name to your collections, "projectA_Users , projectB_Users" and to relate data use the $lookup Aggregate operator to get your relationship. I see something like that on FireBase that you can create a collection inside a document and use find, update, remove on it (here)