Pymongo: findandmodify - returns "no such command"

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 cmd

Since the server expects to findandmodifybe first (BSON dicts seem to be ordered).

Is there any work for this?

+3
4

, dict, mongo . python, SON: http://api.mongodb.org/python/1.4%2B/api/pymongo/son.html. .

, , , findandmodify - .

+6

, JavaScript db.eval().

db.eval('db.runCommand({"findandmodify": "my_collection", "query": {"foo": "bar"}, "update": {"$set": {"status": "queued"}},})')

, , , Python dicts , .

+2

. PyMongo:

Note that the order of the keys in the command document is significant (the "verb" must be the first), so commands that require multiple keys (for example, findandmodify) must use an SON instance or string and kwargs instead of python.

http://api.mongodb.org/python/2.1/api/pymongo/database.html

+1
source

Source: https://habr.com/ru/post/1734738/


All Articles