Alex Rivera | Logout

How can I update/insert Object into inner List in Mongodb?

Asked 2011-01-03T04:35:18.407
10
Blog {
   id:"001"
   title:"This is a test blog",
   content:"...."
   comments:[{title:"comment1",content:".."},{title:"comment2",content:"..."}]    
}

comments is a inner list in blog.

But how can I retrieve only comment1? and How can I insert/update a new comment into the blog?if I get a full blog and insert/update the content into comments List,then save the full blog,how to solve concurrent isuue?

Thanks.

Edit
Report

1 Answer

5

To fetch the embedded document you need fetch the master document and search on his comments embedded document the document you want. There are no way to do better in MongoDB actually.

To insert/update in a embedded document you can use the $push and $set query system to do that.

answered 2011-01-03T08:08:27.603

Your Answer