tags:

views:

76

answers:

2

In 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 when comments is more than 4MB, then this document won't work? We can say, it is hard for it to be more than 4MB, but I guess a system will be a little bit limited if it is limited to the size or number of comments like this. If it is relational model, then there is no such limit except mostly for the disk space.

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

+4  A: 

I think you'll want to paginate 4MB worth of comments.

Per the docs, you should design to the current 4MB limit. So two ideas:

  • Chunk'ify the comments into documents (eg. 1000 per doc)
  • Store each comment as its own document in a "comments" collection
Rob Olmos
+1. This would allow you to also load the comments in chunks (or not at all), which is probably what you want (e.g. when showing only the newest x comments on the first page)
Thilo
+1. Store comments in their own document and link instead of embed.
tylerl
Again, unless your comments will be more than the works of Shakespeare, why do you need all this?
Amala
A: 

Yes, thats a problem if the comments are growing over 4MB. You can change your desgin little with mongo DbRef.

split your document into two as Blog & comments

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

This comment document will hold all the comments related to the specific post.And embed this comments inside 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)

Cheers

Ramesh Vel