Skip to content

Instantly share code, notes, and snippets.

@lega911
Created September 5, 2015 10:32
Show Gist options
  • Save lega911/428b6556814ea15b1683 to your computer and use it in GitHub Desktop.
Save lega911/428b6556814ea15b1683 to your computer and use it in GitHub Desktop.
> db.post.insert({comment: []})
WriteResult({ "nInserted" : 1 })
> db.post.update({}, {$push: {'comment': {text: '1', child:[]}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.post.update({}, {$push: {'comment': {text: '2', child:[]}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.post.update({}, {$push: {'comment.0.child': {text: '3', child:[]}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.post.update({}, {$push: {'comment.0.child.0.child': {text: '4', child:[]}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.post.findOne()
{
"_id" : ObjectId("55eac3ab9363046398e59c70"),
"comment" : [
{
"text" : "1",
"child" : [
{
"text" : "3",
"child" : [
{
"text" : "4",
"child" : [ ]
}
]
}
]
},
{
"text" : "2",
"child" : [ ]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment