简体   繁体   中英

MongoDB multiple collections or multiple databases

We are using .net Core and node.js micro services some of them with mongoDB.

Currently we got the following DB structure :

Every customer gets his own Database. So if we got a micro service for Invoices, every new customer adds 1 new DB for that micro service.

Invoice_customerA
Invoice_customerB 
etc...

While the collections in each such DB remain the same (usually we got 1-3 collections in each DB)

In terms of logic - We choose the right DB by request input in runtime.

I am thinking now about changing it a bit, to start making separation on the collections instead:

So if we take the same example from before this time around this Invoice Service will only have 1 DB,

Invoice_allCustomers

and there will be 1 new collection for each customer in it ( or more if there were more collections for this service).

collection_customerA
collection_customerB

What I am trying to understand is if there is any difference performance wise? Or is it mostly a "cosmetic" change? Or maybe there are some other considerations?

PS If the change is mostly cosmetic I am thinking that the new solution is better for us since we usually got only 1-2 collections per each micro service. And it will be easier to navigate when there are significantly less Databases.

As far as I know in microservices,each service should have its own database. If it is not a different service than you can use one database with different collections in it. It is more of cosmetic changes but I should also warn you that mongodb still has it limits which you can find here . It really depends on the amount of data that will be stored and retrieved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM