Skip to content

Instantly share code, notes, and snippets.

@scotthernandez
Created July 15, 2010 05:22
Show Gist options
  • Save scotthernandez/476540 to your computer and use it in GitHub Desktop.
Save scotthernandez/476540 to your computer and use it in GitHub Desktop.
//1.5.4
> db.test2.insert({
... name : "Something",
... things : [
... {foo : "148091a0719c", bar: 1},
... {foo : "0026080741c6", bar: 0}
... ]
... })
> db.test2.update({name:"Something","things.foo":"148091a0719c"}, {$set:{"things.bar":2}})
can't append to array using string field name [bar]
> db.test2.update({name:"Something","things.foo":"148091a0719c"}, {$set:{"things.$.bar":2}})
> db.test2.findOne();
{
"_id" : ObjectId("4c3e99f0460b000000007ab0"),
"name" : "Something",
"things" : [
{
"foo" : "148091a0719c",
"bar" : 2
},
{
"foo" : "0026080741c6",
"bar" : 0
}
]
}
//1.4.4
> db.test2.findOne();
{
"_id" : ObjectId("4c3e99f0460b000000007ab0"),
"name" : "Something",
"things" : [
{
"foo" : "148091a0719c",
"bar" : 2
},
{
"foo" : "0026080741c6",
"bar" : 0
}
]
}
> db.test2.update({name:"Something","things.foo":"148091a0719c"}, {$set:{"things.$.bar":5}})
> db.test2.findOne();
{
"_id" : ObjectId("4c3e99f0460b000000007ab0"),
"name" : "Something",
"things" : [
{
"foo" : "148091a0719c",
"bar" : 5
},
{
"foo" : "0026080741c6",
"bar" : 0
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment