Skip to content

Instantly share code, notes, and snippets.

@kontinuity
Created May 7, 2012 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kontinuity/2626580 to your computer and use it in GitHub Desktop.
Save kontinuity/2626580 to your computer and use it in GitHub Desktop.
Mongo pull discrepancy
> var x = {x: 0, y: [ {a:1,b:100}, {a:2,b:101} ]}
> db.tester.drop()
true
> db.tester.insert(x)
> db.tester.findOne()
{
"_id" : ObjectId("4fa7803455bdd0772d514ffc"),
"x" : 0,
"y" : [
{
"a" : 1,
"b" : 100
},
{
"a" : 2,
"b" : 101
}
]
}
> db.tester.update({}, {$pull: {y: {$elemMatch: {a: 2}}}}, false, true)
> db.tester.findOne()
{
"_id" : ObjectId("4fa7803455bdd0772d514ffc"),
"x" : 0,
"y" : [
{
"a" : 1,
"b" : 100
},
{
"a" : 2,
"b" : 101
}
]
}
> db.tester.update({}, {$pull: {y: {$elemMatch: {a: 2,b:101}}}}, false, true)
> db.tester.findOne()
{
"_id" : ObjectId("4fa7803455bdd0772d514ffc"),
"x" : 0,
"y" : [
{
"a" : 1,
"b" : 100
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment