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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM