Mongolian democratic philosophy

I am creating a system where a company has multiple users, clients, etc. I am unable to decide whether to create "objects" such as users, individual collection, or inline company document documents.

Company (Object) ->
    Users (Object) ->
        Profile (Object) ->
        History (Object) ->
    Customers ->


I'm stuck with a relational database problem right now, and not sure what the "correct" way to do this is with NoSQL. What are your thoughts?

What happens when a double inline document (like company> users-> history) gets ridiculously large?

What are some other considerations for the embedded document (if any)? Again, I tend to think relationally.

Thanks in advance.


source to share

3 answers has some schema design tips, there are also various 10Gen member presentations like this one: sts-04-2012-mongo-and-nosql-schema.pdf

Given the likely number of users in the company and the likely number of story objects, I think you probably need a separate collection for each one.



I can give general advice here, but in the end it's up to you which approach you take. The question you need to ask in order to determine whether to insert or reference is:

What information do you need to return when receiving a document for most requests?

It can be simple or difficult - if 99% of your queries return the same 5 fields, the answer will be obvious. If you rarely need a piece of data, then this is a candidate for a separate collection. You will need a second lookup to get this data and some type of link between them, but the rarity makes this overhead information acceptable.

Naturally, if your data and return values ​​are not that clear, this becomes a more difficult question.

If you want a frequent field, but not all of it is (for example, the last 5 entries in history), then store them, fixed size, in the main document and the rest in a separate collection. This causes some duplication and complicates your updates, but can be a good tradeoff in terms of speed.

In cons terms, a large inline document isn't bad in and of itself, but growing, especially one with unlimited growth, can be bad. Each time the document grows, chances are that it will be too large for the allocated space, which means that it will need to be moved. Not only does this fragment fragment your data a little, it can be an expensive operation to move a large document around, allocate new space - especially if you do this a lot. The Padding Factor explains this pretty well (adding a fill factor when the move is triggered):

Hope it helps!



If you do not need to request and receive statistics, etc. on the linked data yourself, make it inline, which will also speed up the query. If you need to extract this data for any purpose, create new collections for it.



All Articles