MongoDB查詢空值
我的收藏(MongoDB v 2.0.2)有以下記錄:
db.organization.find({}) { "_id" : 1001, "path" : [ ], "parent" : null } { "_id" : 1002, "path" : [ 1001 ], "parent" : NumberLong(1001) }
組織有索引:
db.organization.ensureIndex({"path":1}); db.organization.ensureIndex({"parent":1},{sparse:false});
(注意我放了awarnes sparse:false– 授予null被索引)
但是,執行:
db.organization.find({"parent":null})
返回空集.哪裡不對?先謝謝你
我遇到過同樣的問題.閱讀以下檔案後
>ofollow,noindex" target="_blank">querying and nulls
我嘗試查詢不同的BSON元素型別,並發現我的null被表示為BSON元素型別6(未定義,不推薦使用),而不是預期的BSON元素型別10(null).
db.collection.find({ field: { "$type" : 6} };
http://stackoverflow.com/questions/9312067/mongodb-queries-with-null-value
本站文章除註明轉載外,均為本站原創或編譯
轉載請明顯位置註明出處:MongoDB查詢空值