I believe that there is a bug in pymongo (or at least the documentation) that makes it impossible to execute the request findandupdate.
This is what happens. When I run:
result = db.command({
'findandmodify': 'my_collection',
'query': {'foo': 'bar'},
'update': {'$set': {'status': 'queued'}},
})
A request that is actually sent to the server:
{ 'query': {'foo': 'bar'}, 'findandmodify': 'my_collection', … }
Note that the argument is first query, and the findandmodifysecond.
But this makes the server throw:
OperationFailure: command {'query': {'foo': 'bar'}, 'findandmodify': 'my_collection', ...} failed: no such cmdSince the server expects to findandmodifybe first (BSON dicts seem to be ordered).
Is there any work for this?