If a MongoDB document is a comment blog post, will it not scale with comments over 4 MB?

On the MongoDB page: http://www.mongodb.org/display/DOCS/Inserting

doc = { author: 'joe', created : new Date('03/28/2009'), title : 'Yet another blog post', text : 'Here is the text...', tags : [ 'example', 'joe' ], comments : [ { author: 'jim', comment: 'I disagree' }, { author: 'nancy', comment: 'Good post' } ]} db.posts.insert(doc); db.posts.find( { "comments.author" : "jim" } ) 

Is it true that with comments over 4 MB, this document will not work? We can say that it is no more than 4 MB for it, but I think that the system will be a little limited if it is limited by the size or number of comments like this. If this is a relational model, then there is no such limit, except mainly for disk space.

Or is there another way to handle comments so that it can be of any size?

+4
source share
2 answers

I think you will want to highlight 4 megabytes of comments.

In documents, you should make up the current limit of 4 MB. So, two ideas:

  • Chunk'ify comments in documents (e.g. 1000 for each document)
  • Save each comment as your own document in the comment collection.
+5
source

Yes, this is a problem if comments grow by more than 4 MB. You can change your desgin a bit with mongo DbRef .

split your document into two in the form of a blog and comments

 var comment = { id:"xx", comments : [ { author: 'jim', comment: 'I disagree' }, { author: 'nancy', comment: 'Good post' } ]} } 

This comment document will contain all comments related to a specific post. And embed these comments on your blog using Dbref, something like

  db.comments.save(comment) var doc = { author: 'joe', created : new Date('03/28/2009'), title : 'Yet another blog post', text : 'Here is the text...', tags : [ 'example', 'joe' ], comments : [ new DBRef('comments', comment ._id) ] } db.blog.save(doc) 
+1
source

All Articles