$all parameter in mongodb does not work with ObjectId list

痴心易碎 提交于 2019-12-12 03:15:44

问题


I retrieve a list of ObjectId and I want to retrieve all object in my mongo database using the parameter $all

I'm using pymongo and my request look 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 do this request:

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

It returns me the good object

Anyone know why it does not work?


回答1:


That query does not make sense. You are asking for the unique and single-valued _id field to have all of two distinct values at the same time.

I think you want $in:

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


来源:https://stackoverflow.com/questions/9977499/all-parameter-in-mongodb-does-not-work-with-objectid-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!