Reputation: 4941
I am running the below query and It does not work. When I run the query part in mongo UI, it returns me expected result. I am using UMongo. But it does not update the document as expected.
db.system.js.save ({
_id:"script_1",
value: function() {
print("in function>>");
db.data.find({"$and":
[{"title":{$regex : '.*Green Red.*', $options : 's'}},
{"editor.key": {"$in": ["74014","45339"]}}, {"types" : {"$in": ["Notes"]}}]}).forEach(
function(docMatch){
print("Matching document found");
db.data.update(docMatch,
{$set:{"editor.key": "05335","editor.value": "editor1",
"editor.email": "[email protected]"}
}, false, true);
}
);
db.data.reIndex();
}
});
db.eval("script_1()");
I do see "Matching document found" in the mongo logs but does not update. Shows below message too in the logs.
Thu Sep 19 11:03:43 [conn1279] warning: ClientCursor::yield can't unlock b/c of recursive lock ns
Thanks for you help !
Upvotes: 0
Views: 3397
Reputation: 691
I'm not sure exactly what the problem is without having your data and being able to run your query. However, there are lots of issues with this code:
If this is code generated by UMongo, I recommend moving away from UMongo and working with the officially supported mongo shell.
In order to fix your call to update, try running something like this in the mongo shell:
db.data.update(
{
"title": {$regex : '.*Green Red.*', $options : 's'},
"editor.key": {"$in": ["74014","45339"]},
"types" : "Notes"
},
{
$set: {
"editor.key": "05335",
"editor.value": "editor1",
"editor.email": "[email protected]"
}
},
false,
true
);
Upvotes: 2