Database Reference
In-Depth Information
Approach: Embedding All Comments
This design embeds the entire discussion of a comment thread inside of its parent node docu-
ment.
Consider the following prototype topic document:
{ _id : ObjectId (...),
...,
metadata : {
...
comments : [
{ posted : ISODateTime (...),
author : { id : ObjectId (...), name : 'Rick' },
text : 'This is so bogus ... ' },
... ],
}
}
This structure is only suitable for a chronological display of all comments because it embeds
comments in chronological order. Each document in the array in the comments contains the
comment's date, author, and text.
To support threading using this design, we would need to embed comments within comments,
using a structure more like the following:
{ _id : ObjectId (...),
... lots of topic data ...
metadata : {
...,
replies : [
{ posted : ISODateTime (...),
author : { id : ObjectId (...), name : 'Rick' },
text : 'This is so bogus ... ' ,
replies : [
{ author : { ... }, ... },
... ]
}
... ]
}
}
Search WWH ::




Custom Search