简体   繁体   中英

MongoDB - MANY documents or MANY collections

I am currently working on a service that stores products owned by multiple stores, and I am trying to figure how is the best way of structuring the DB. The only problem is that products are from different domains, like, clothes, toys, electronics and sold by different sellers.

First idea that came to mind was having different collections for each seller, but I see this as a headache, having to manage different DB connections.

The idea of storing all products in the same document seems bad to me, because they are from different domains.

The only idea that I believe could work in this case is like this: Let's say we have 3 stores: Store One, Store Two, Store Three. I would create a document for each store like this: products_storeone , products_storetwo , products_storethree and access them based on an identifier each store has. Now, each store will have multiple documents to store different things like products_identifier , users_identifier , orders_identifier .

Do you consider this is a good idea? Please tell me your opinion on what could be the best way of achieving a structure for storing items for each store independently, without mixing them.

After some calculation, there will be maximum 50 documents for each store. I don't see this as a way to big number to handle like 1.000 stores. Do you think 50.000 documents are too much? Impacts performance? Any tips in order to achieve high performance for queries are more than welcome.

Thanks!

You can make an single db "products" and it will be an array of objects and each will be a single product. Each product will have "store" and "category" attribute by which we query efficiently.

Hope this can be of help.

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