$ all parameter in mongodb does not work with ObjectId list

I am retrieving the ObjectId list and want to get the whole object in my mongo database using the $ all parameter

I am using pymongo and my query looks like this:

db.database.collection.find({ "_id" : { "$all" : [ObjectId('4ee371837c93dd33dc000003'),ObjectId('4eef9f647c93dd1a90000000')] } }) 

but the cursor count returned by the request is 0 but when I make this request:

 db.database.collection.find_one({ "_id" : ObjectId('4ee371837c93dd33dc000003')}) 

He returns me a good object

Does anyone know why this is not working?

0
source share
1 answer

This request does not make sense. You request a unique and unique _id field to have all two different values ​​at the same time.

I think you want $in :

 db.database.collection.find({ "_id" : { "$in" : [ObjectId('4ee371837c93dd33dc000003'), ObjectId('4eef9f647c93dd1a90000000')] } }) 
+7
source

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


All Articles