Help with DB design (collections)

Hi all, freshman here :star: So hope I’ve followed the guidelines correctly

I’ve done some reading upon whether to have multiple collections vs not. And far as I can tell it seems to be almost use case specific (not much help haha). So I guess best case would be to pitch my use case and see whether it is the best approach

Our setup is per client base, so for clientA we will have: clientA_users, clientA_stock. Would it be better in that approach or to rather have: users, stock → with a field to help identify which client a document belongs to?

Much appreciated

You may get trouble with too many collections - Massive Number of Collections | MongoDB

So i prefer using client id within the same collection

1 Like

With out looking at the code its a little hard to exactly comprehend your concern. Some things to consider are as follows.

  1. Too many intertwined collections would make the queries very complex
  2. Having its better to have multiple documents in a collection rather than number of collections. NoSql architecture makes mongodb scale extremely well a collection with half a billion documents if queried correctly still would not be a cause of concern
  3. Keep an eye out on the size of the document even though the limit always the document to be fairly big but deep nesting and the chained fields do hit a limit if the field names are excessively large
  4. In your particular case having a pointer in the stock field is a good option its just a matter of getting used to and making use of the aggregation framework will amaze you at how robust it is.

Having said all that it is worthy to mention that you have to have a good understanding about the approach you take on how you structure your data and the trade offs associated with it.