Database Reference
In-Depth Information
Embed all comments in the “parent” document
This approach provides the greatest possible performance for displaying comments at the
expense of flexibility: the structure of the comments in the document controls the display
format. (You can, of course, re-sort the comments on the client side, but this requires extra
work on the application side.) The number of comments, however, is strictly limited by
MongoDB's document size limit.
Store comments separately from the “parent,” but grouped together with each other
This hybrid design provides more flexibility than the pure embedding approach, but
provides almost the same performance.
Also consider that comments can be threaded , where comments are always replies to a “par-
ent” item or to another comment, which carries certain architectural requirements discussed
next.
Approach: One Document per Comment
If we wish to store each comment in its own document, the documents in our comments col-
lection would have the following structure:
{
_id : ObjectId (...),
node_id : ObjectId (...),
slug : '34db' ,
posted : ISODateTime (...),
author : {
id : ObjectId (...),
name : 'Rick'
},
text : 'This is so bogus ... '
}
This form is only suitable for displaying comments in chronological order. Comments store
the following:
▪ The node_id field that references the node parent
▪ A URL-compatible slug identifier
Search WWH ::




Custom Search