Error: findAndModifyFailed failed - "errmsg" : "no such command: '_id'" - "codeName" : "CommandNotFound"
I am trying to run the following MongoDB query
db.getCollection('requests').findAndModify({"_id" : 1598075878120}, {$set: {"success" : false}})
but running into folowing exception
Failed to execute script.
Error: findAndModifyFailed failed: {
"ok" : 0,
"errmsg" : "no such command: '_id'",
"code" : 59,
"codeName" : "CommandNotFound"
}
Details:
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:736:1
@(shell):1:1
1 Answer
5 years ago by cody
Wrong number of parameters passed to findAndModify it should be like following
db.getCollection('requests').findAndModify( {
query: {"_id" : 1598075878120},
update: {$set: {"success" : false}}
});
5 years ago by Karthik Divi