Blog posts and comments For example, the blog post has a title content, corresponding to a number of comments, comments have comments, comments and other content. (1) Insert a blog post: Db.blog.insert ({'_id':' One','title':'This is blog Title1','content':'This is blog Content1'})(2) Update a blog post db.blog.update ({'_id':' One'}, {$set: {'title':'This is blog title2','content':'This is blog Content2'}})(3) to update a blog post, insert db.blog.update if it does not exist ({'_id':' A'}, {$set: {'title':'This is blog title4','content':'This is blog content4'}}, {upsert:true})(4Add a comment to the blog post db.blog.update ({'_id':' One'}, {$push: {'Comments':{'User':'User1','content':'Reviews 1'}}})(5Delete the Post's comment db.blog.update based on the criteria ({'_id':' One'}, {$pull: {'Comments':{'User':'User1'}}})(6use $addtoset to avoid adding duplicate data db.blog.update ({'_id':' One'}, {$addToSet: {'Comments':{'User':'User1','content':'Reviews 1'}}})(7) with $addtoset &BULK INSERT Data db.blog.update $each Union operation ({'_id':' One'}, {$addToSet: {'Comments':{'$each':[ {'User':'User1','content':'Reviews 1'}, {'User':'User2','content':'Reviews 2'}, {'User':'User3','content':'Reviews 3'}, ]}}})
MongoDB Insert/update/one2many Case