mongodb查詢欄位為null和存在不存在
阿新 • • 發佈:2020-12-21
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