mongodb查询字段为null和存在不存在

https://blog.csdn.net/majinggogogo/article/details/48913007

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

db.c.find({y: null})

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

db.c.find({“y”: {$type : 10}})
$type为10表示Null

或者
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}})

https://mongoing.com/docs/tutorial/query-for-null-fields.html

原文地址:https://www.cnblogs.com/liuzhenwei/p/14166542.html