我正在执行以下查询,它完美地工作,并为我提供了符合类型过滤器
的部分文档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
有关如何进行此查询的任何线索?
答案 0 :(得分:19)
这应该有效:
{phoneNumber:/^\+/ ,$and:[{devices:{$exists:true}},{devices:{$not:{$type:3}}}]}