gpt4 book ai didi

mongodb - mongodb中类型不相等的查询

转载 作者:IT老高 更新时间:2023-10-28 13:11:39 27 4
gpt4 key购买 nike

我正在执行以下查询,该查询完美运行,并为我带来了符合类型过滤器的文档部分

db.users.find({phoneNumber:/^\+/, devices:{$exists:true, $type:3}});

但是我试图获取所有存在但不是类型 3(对象)的设备,我可以尝试每种类型 [http://docs.mongodb.org/manual/reference/operator/query/type/] ,但想知道是否可以否定我尝试过的类型 3

db.users.count({phoneNumber:/^\+/, devices:{$exists:true, $type: { $neq: 3}}});
db.users.count({phoneNumber:/^\+/, devices:{$exists:true, $type: { $not: 3}}});
db.users.count({phoneNumber:/^\+/, devices:{$exists:true, $type: { $not: {$eq:3}}}});

但是它们都抛出相同的异常

exception: type not supported for appendMinElementForType

关于如何进行此查询的任何线索?

最佳答案

这应该可以按预期工作:

{phoneNumber:/^\+/ ,$and:[{devices:{$exists:true}},{devices:{$not:{$type:3}}}]}

mongodb 文档中的这个注释可能有助于了解这里发生了什么(复制自 MongoDB reference docs - $and operator manual page - 重点是我的):

MongoDB provides an implicit AND operation when specifying a comma separated list of expressions. Using an explicit AND with the $and operator is necessary when the same field or operator has to be specified in multiple expressions.

关于mongodb - mongodb中类型不相等的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20744123/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com