因此,我試圖查找所有具有字段集并且不為空的記錄。我嘗試使用$exists,但是根據MongoDB文檔,此查詢將返回等于null的字段。$exists 確實匹配包含存儲空值的字段的文檔。所以我現在假設我必須做這樣的事情:db.collection.find({ "fieldToCheck" : { $exists : true, $not : null } })但是,無論何時嘗試,我都會收到錯誤消息[invalid use of $not] 有人知道如何查詢此消息嗎?
4 回答

肥皂起泡泡
TA貢獻1829條經驗 獲得超6個贊
使用$ne(“不相等”)
db.collection.find({ "fieldToCheck": { $exists: true, $ne: null } })

一只萌萌小番薯
TA貢獻1795條經驗 獲得超7個贊
假設我們有一個如下所示的集合:
{
"_id":"1234"
"open":"Yes"
"things":{
"paper":1234
"bottle":"Available"
"bottle_count":40
}
}
我們想知道瓶子領域是否存在嗎?
答:
db.products.find({"things.bottle":{"$exists":true}})

30秒到達戰場
TA貢獻1828條經驗 獲得超6個贊
我發現這對我有用
db.getCollection('collectionName').findOne({"fieldName" : {$ne: null}})
- 4 回答
- 0 關注
- 1488 瀏覽
添加回答
舉報
0/150
提交
取消