2013-12-23 41 views
7

即时通讯做下面的查询,其完美的工作,使我有一项符合该类型的过滤器的文件的一部分查询与类型MongoDB中不等于

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 

有关如何执行此查询的任何线索?

回答

13

这应该工作:

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