Defining the CommentThread Model

The goal of the comments model is to support nested comments. In MongoDB there are a couple different methods to do that. You can store each comment as an individual document and provide a link to parent objects, or you can store all comments for a thread in a single document. Either way works, but they have very different implementations and consequences.

Storing the comment tree in a single document makes it simple and fast to load from MongoDB. The drawback is that because there is not a fixed depth for comments, the entire reply structure needs to be saved when new comments are added. Also, you need to get the entire document to get any of the comments.

Storing the comments as individual documents means that ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.