Wednesday, 15 June 2011

Difference between Embedded Array of Ids and Normalized style in MongoDB -



Difference between Embedded Array of Ids and Normalized style in MongoDB -

so, have been watching this video in order larn mongodb info modeling. in 1 many relationship, speaker talks 3 different kinds:

embedded array / array keys: in particular document have field array references other documents (for example, blog_posts attribute in user document store ids of blog posts user has created) embedded tree: rather having array references other things, have documents in documents, embedded. normalized: have 2 collections , references between each other.

so, difference between embedded array keys , normalized kind? isn't embedded array doing references 2 collection?

the difference simple (and unfortunately bit confusingly presented in video).

imagine modeling blog post (post) , comments (comment).

embedded array: post document contains array of of ids of of comment documents. comment stored in separate document (and/or collection). tree: post document contains embedded comments. aren't stored in distinct documents or in own collection. while performs well, size limit of bson documents beingness 16mb makes potentially more hard work with. normalized: post document, , comments stored separately. comment document in case has foreign-key reference post. so, might have field called postid example. reference post related comment. pattern different #1 post document not contain list of comments. so, while alternative makes number of comments unbounded/unlimited, create retrieval of comments more inefficient without specific indexes beingness built (like postid, commentdate might useful).

mongodb

No comments:

Post a Comment