c# - Relations efficiency mongodb relational-storage patterns, when to embed? -


just moved traditional sql server mongodb , trying figure out relational storage pattern should using, or when use embed documents?

i point out not discussion if should use relational sql database or nosql database, several reasons nosql suits needs of project more sql databases.

reason asking lot of advice people receive points in direction of using mongodb how on traditional sql server, , wondering if advice should follow or if lot of people stuck in mind-set of how traditional sql servers function.

application writing uses lot of one-to-many , many-to-many relations (however each entity may have limited amount of child entities), , more lookups have 1 entity , want find relational counterpart, in traditional sql world 2 or tree different tables, in mongodb embedded documents can 1 or 2 collections. (i not saying not possible achieve on traditional sql servers)

since working mongodb rather sql server, i'll show example of account system use. way "master account" , "user accounts", 1 user must have 1 master account , 1 master account can have multiple user accounts.

the following way how embedded additional users master account.

account {     _id: objectid(),     username: "some users username",     users: [         {             username: "first additional user name"         },         {             username: "second additional user name"         }     ] } 

and more traditionally sql way, though requires additional query.

account (master account) {     _id: objectid(),     username: "some users username" }  users (user account) {     _id: objectid(),     account_id: ref account objectid(),     username: "an additional user name" } 

given system has 3 000 accounts , total of 14 000 user accounts of above ways work quite (on average 1 master account has 4 or 5 user accounts), lets multiply these numbers ten-twenty-thirty sky limit (still 4 5 user accounts per master account) imagine 1 of above ways preferred?

the remainder of system acts lot alike, entities have have hundreds if not thousands of child entities traditional sql way preferred or it? work entities has 10 40 child entities.

lot's of real-time reports made within system, , meat in these reports gathered these relational entities, on sql server joins create these reports mind boggling complex , inefficient, on mongodb simple query run has slight knowledge of queries can understand (in case talking embed documents) , hell lot quicker on sql server, quite new nosql , how embed approach perform on time when growth of data high?

nosql data redudancy optimization approach story.

in mongo, should embed references rather full documents. can embed partial documents. example, if need know both user's id , name, won't add reference containing id both.

in other hand, users collection contain full user documents more data (i.e. email, date added, date modified...). is, if need extended data, need query users collection user reference (i.e. id property) , that's all.

nowadays disk storage cheap , why need play data redundancy said above.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -