On Thu, 14 Nov 2013 13:46:04 GMT, Sönke Ludwig wrote:
On Thu, 14 Nov 2013 13:11:39 GMT, Drasha wrote:
Should be:collection.update( [ "name": Bson("Tom"), "state": Bson("active"), "rating": serializeToBson(["$gt": 10]) ], ["$inc": ["score": 1]] ); // or collection.findAndModify( [ "name": Bson("Tom"), "state": Bson("active"), "rating": serializeToBson(["$gt": 10]) ], ["$inc": ["score": 1]] );
The "sort" field is not supported for
update
andfindAndModify
, though. But it can be done manually using the samerunCommand
call as in JS:auto cmd = Bson.emptyObject; cmd["findAndModify"] = Bson("people"); cmd["query"] = Bson([ "name": Bson("Tom"), "state": Bson("active"), "rating": serializeToBson(["$gt": 10]) ]); cmd["sort"] = Bson(["rating": Bson(1)]); cmd["update"] = serializeToBson(["$inc": ["score": 1]]); db.runCommand(cmd);
Hpmf... I swear this was the first thing I tried, but got some errors regarding type incompatibility. I guess I should have tried harder :-)
Thanks