Skip to content

Instantly share code, notes, and snippets.

@ymek
Created September 13, 2012 00:56
Show Gist options
  • Select an option

  • Save ymek/3711089 to your computer and use it in GitHub Desktop.

Select an option

Save ymek/3711089 to your computer and use it in GitHub Desktop.
> db.things.insert({'content' : {'foo': []}})
> db.things.find()
{ "_id" : ObjectId("50512dd15e5110032d1fa00d"), "content" : { "foo" : [ ] } }
> db.things.update({ _id : ObjectId("50512dd15e5110032d1fa00d") }, { $set : { 'content.foo.0' : {bar: 5} } })
> db.things.find()
{ "_id" : ObjectId("50512dd15e5110032d1fa00d"), "content" : { "foo" : [ { "bar" : 5 } ] } }
> db.things.update({ _id : ObjectId("50512dd15e5110032d1fa00d") }, { $set : { 'content.foo.1' : {bar: 5} } })
> db.things.find()
{ "_id" : ObjectId("50512dd15e5110032d1fa00d"), "content" : { "foo" : [ { "bar" : 5 }, { "bar" : 5 } ] } }
> db.things.update({ _id : ObjectId("50512dd15e5110032d1fa00d") }, { $set : { 'content.foo.0' : {bar: 8} } })
> db.things.find()
{ "_id" : ObjectId("50512dd15e5110032d1fa00d"), "content" : { "foo" : [ { "bar" : 8 }, { "bar" : 5 } ] } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment