MongoDb and C# : Embedded or Reference Document -


is document references in mongodb recommended method or embedded documents right way ? questions comes in context of following.

class objecttype1 { objectid id; objecttype2 type2element; }  class objecttype2 { objectid id; } 

i understand use mongodbref reference objecttype2 element in first class, wasn't able locate fetchdbrefas method (am using official mongodb c# driver, may looking @ wrong place/namespace).

what recommended way link entities if required in mongodb, working c# ? thanks

to answer question shortly: depends on use case.

some rules follow when design own db schema:

  • if in code need both objecttype1 , objecttype2 @ same time suggest use embedded approach because need 1 query perform crud on them. furthermore, more logical because info need @ same place in db.

  • if of times in code need objecttype2, separate them in 2 collections.

this part of official docs has lots more info: https://docs.mongodb.com/manual/core/data-modeling-introduction/


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -