Created
August 15, 2012 03:11
-
-
Save scoates/3355357 to your computer and use it in GitHub Desktop.
MongoDB: findandmodify seems to use the wrong query on the update command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.runCommand({ findAndModify: 'assets', query: {$or: [ { "_id" : "4ff70c97c87a97bc7f000002" }, { "_id" : ObjectId("4ff70c97c87a97bc7f000002") } ]}, update: {$set: {private: true}}, new: true, upsert: false }) | |
{ | |
"lastErrorObject" : { | |
"updatedExisting" : true, | |
"n" : 1, | |
"connectionId" : 1317, | |
"err" : null, | |
"ok" : 1 | |
}, | |
"value" : { | |
REDACTED | |
} | |
} | |
> db.system.profile.find().forEach(printjson) | |
{ | |
"ts" : ISODate("2012-08-15T02:51:43.240Z"), | |
"op" : "query", | |
"ns" : "gimmebar.assets", | |
"query" : { | |
"$or" : [ | |
{ | |
"_id" : "4ff70c97c87a97bc7f000002" | |
}, | |
{ | |
"_id" : ObjectId("4ff70c97c87a97bc7f000002") | |
} | |
] | |
}, | |
"ntoreturn" : 1, | |
"nscanned" : 1, | |
"nreturned" : 1, | |
"responseLength" : 657, | |
"millis" : 0, | |
"client" : "0.0.0.0", | |
"user" : "" | |
} | |
{ | |
"ts" : ISODate("2012-08-15T02:51:43.241Z"), | |
"op" : "update", | |
"ns" : "gimmebar.assets", | |
"query" : { | |
"_id" : ObjectId("4ff70c97c87a97bc7f000002"), | |
"$or" : [ | |
{ | |
"_id" : "4ff70c97c87a97bc7f000002" | |
}, | |
{ | |
"_id" : ObjectId("4ff70c97c87a97bc7f000002") | |
} | |
] | |
}, | |
"updateobj" : { | |
"$set" : { | |
"private" : true | |
} | |
}, | |
"nscanned" : 1, | |
"fastmod" : true, | |
"millis" : 0, | |
"client" : "0.0.0.0", | |
"user" : "" | |
} | |
{ | |
"ts" : ISODate("2012-08-15T02:51:43.241Z"), | |
"op" : "query", | |
"ns" : "gimmebar.assets", | |
"query" : { | |
"_id" : ObjectId("4ff70c97c87a97bc7f000002") | |
}, | |
"ntoreturn" : 1, | |
"idhack" : true, | |
"responseLength" : 657, | |
"millis" : 0, | |
"client" : "0.0.0.0", | |
"user" : "" | |
} | |
{ | |
"ts" : ISODate("2012-08-15T02:51:43.241Z"), | |
"op" : "command", | |
"ns" : "gimmebar.$cmd", | |
"command" : { | |
"findAndModify" : "assets", | |
"query" : { | |
"$or" : [ | |
{ | |
"_id" : "4ff70c97c87a97bc7f000002" | |
}, | |
{ | |
"_id" : ObjectId("4ff70c97c87a97bc7f000002") | |
} | |
] | |
}, | |
"update" : { | |
"$set" : { | |
"private" : true | |
} | |
}, | |
"new" : true, | |
"upsert" : false | |
}, | |
"ntoreturn" : 1, | |
"responseLength" : 763, | |
"millis" : 0, | |
"client" : "127.0.0.1", | |
"user" : "" | |
} | |
{ | |
"ts" : ISODate("2012-08-15T02:51:47.096Z"), | |
"op" : "command", | |
"ns" : "gimmebar.$cmd", | |
"command" : { | |
"profile" : 0 | |
}, | |
"ntoreturn" : 1, | |
"responseLength" : 58, | |
"millis" : 0, | |
"client" : "127.0.0.1", | |
"user" : "" | |
} | |
> |
Looks like the _id is appended to the query, explicitly, here, but that doesn't explain leaving the $or clause. https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/find_and_modify.cpp#L119
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note on line 44 how it queries explicitly for the _id (assuming this is from the first query), and also uses the $or block. This doesn't seem right (and makes for strange explain() results (an empty BasicCursor for the $or clause).