Pennesi Diego
Pennesi Diego

Reputation: 35

Mongo DB: Single collection per user whit all interaction, or Multiple Collections per argument?

Good Evening. I'm pretty new to mongo db and i'm planning to make an app who will work whit Nosql(MongoDB). The scope of the app is pretty simple: Register a profile Request item to a shopper Fulfill and sent payment notice.

If i would make this whit SQL i would create a User Table, A Request Item Table a sending Paymen Table.

I would, also in order to learn something, to make it whit NOsql, and i choose mongo. I could create 3 collection and put every different document and make a search every time i need. OR, and this is the question, COULD i create collection for EVERY user, and inside every user put every interaction of the very same user. So if i need to search for User10 order and paymen, i would look only inside User10 collection and search for every item he\she requested.

But on the other hand, how much can affect me if i need to search all order in a specific timeframe? It should be slower than SQL i suppose.

Is a acceptable way to do this, there are some backdraw i did not yet seen, or is discouraged in order to make another approach?

The backend would be write in Java, meanwile the app (for...reason) would be write in Xamarin.Form .

Upvotes: 1

Views: 304

Answers (1)

Tom Slabbaert
Tom Slabbaert

Reputation: 22296

While this is possible I would personally recommend against this as this is considered an anti pattern, you should read this article about this very topic.

I would personally ask myself what are the advantages of this approach that i'm hoping to gain? if quick queries at a user level is what you seek this should not be a problem with sufficient indexes. (on user_id and on timeframe ).

There are other standard solutions built to deal with scale like collection sharding. From my personal experience MongoDB deals with scale very well, It sounds like this is a personal project to learn from which probably means you'll never really reach hyper scale, The first barrier you'll probably encounter is hardware.

Upvotes: 1

Related Questions