mongodb 中的 $all 参数不适用于 ObjectId 列表 [英] $all parameter in mongodb does not work with ObjectId list
本文介绍了mongodb 中的 $all 参数不适用于 ObjectId 列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我检索了一个 ObjectId 列表,我想使用参数 $all 检索我的 mongo 数据库中的所有对象
I retrieve a list of ObjectId and I want to retrieve all object in my mongo database using the parameter $all
我正在使用 pymongo,我的请求如下所示:
I'm using pymongo and my request look like this :
db.database.collection.find({ "_id" : { "$all" : [ObjectId('4ee371837c93dd33dc000003'),ObjectId('4eef9f647c93dd1a90000000')] } })
但是请求返回的游标计数为0但是当我执行此请求时:
but the cursor count returned by the request is 0 but when I do this request:
db.database.collection.find_one({ "_id" : ObjectId('4ee371837c93dd33dc000003')})
它还给我好物
有人知道为什么它不起作用吗?
Anyone know why it does not work?
推荐答案
该查询没有意义.您要求唯一且单值的 _id
字段所有同时具有两个不同的值.
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.
我想你想要$in
:
db.database.collection.find({ "_id" : {
"$in" :
[ObjectId('4ee371837c93dd33dc000003'),
ObjectId('4eef9f647c93dd1a90000000')] } })
这篇关于mongodb 中的 $all 参数不适用于 ObjectId 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文