Skip to content

Instantly share code, notes, and snippets.

@scoates
Created August 15, 2012 03:11
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 scoates/3355357 to your computer and use it in GitHub Desktop.
Save scoates/3355357 to your computer and use it in GitHub Desktop.
MongoDB: findandmodify seems to use the wrong query on the update command
> 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" : ""
}
>
@scoates
Copy link
Author

scoates commented Aug 15, 2012

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).

@scoates
Copy link
Author

scoates commented Aug 15, 2012

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