PYMONGO - How to use the $ request in a statement with MongoID?

So, I'm trying to use the $ in operator in Pymongo, where I want to search using the MongoID group.

First I have this query to find an array of MongoIDs:

findUsers = db.users.find_one({'_id':user_id},{'_id':0, 'f':1})

If I print findUsers['f'], it looks like this:

[ObjectId('53b2dc0b24c4310292e6def5'), ObjectId('53b6dbb654a7820416a12767')]

These object identifiers are user identifiers, and I want to find all the users in the user collection with this array of ObjectID. So I thought:

foundUsers = db.users.find({'_id':{'$in':findUsers['f']}})

However, when I type foundUsers, the result is as follows:

<pymongo.cursor.Cursor object at 0x10d972c50>

which is not what I usually get when I print a request: (

What am I doing wrong here?

Many thanks.

Also for reference, I requested in the mongo shell and it works as expected:

db.users.find({_id: {$in:[ObjectId('53b2dc0b24c4310292e6def5'), ObjectId('53b6dbb654a7820416a12767')]}})
+4
1

findOne() find() MongoDB. findOne . find() mongoDB. , . , mongo, , mongo -, 20 - :

mongo db.collection.find(). .

, . shell mongo, var, 20 [1] 20 .

http://docs.mongodb.org/manual/core/cursors/

pymongo , , :

http://api.mongodb.org/python/current/api/pymongo/cursor.html

, . find() :

for doc in findUsers:
    print(doc)
+1

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


All Articles