mongodb查询的null、存在于不存在

查询集合c中y的值为null或者不存在

>db.c.find( { “y” : null } )

 

查询集合c中y的值为null,(仅返回y的值为null的数据,不会返回不存在的)

>db.c.find( { “y” : { $type : 10 } } )

还有一种写法如下

>db.c.find({“y”:{“$in”:[null], “$exists”:true}})

 

查询集合c中y的值不存在(不会返回y的值为null的数据)

>db.c.find( { “y” : { $exists : false } } )

 

查询集合c中y的值不为null且存在的记录

 

>db.c.find( { “y” : {"$ne":null, $exists: true }} )

或者:>db.c.find( { “y” : {"$ne":null }} )

posted @ 2017-11-24 10:38  春雨如约而来  阅读(12600)  评论(0编辑  收藏  举报