本文介绍了具有空值的MongoDB查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的收藏集(MongoDB v 2.0.2)具有以下记录:
My collection (MongoDB v 2.0.2) has following records:
db.organization.find({})
{ "_id" : 1001, "path" : [ ], "parent" : null }
{ "_id" : 1002, "path" : [ 1001 ], "parent" : NumberLong(1001) }
organization
具有索引:
db.organization.ensureIndex({"path":1});
db.organization.ensureIndex({"parent":1},{sparse:false});
(请注意,我输入了awarnes sparse : false
-授予对null进行索引)但是,执行:
(note I put awarnes sparse : false
- to grant that null is indexed)But, executing:
db.organization.find({"parent":null})
返回空集.怎么了?预先谢谢你
Returns empty set. What is wrong? Thank you in advance
推荐答案
我遇到了同样的问题.阅读以下文档后
I had the same issue. After reading the following documents
- querying and nulls
- BSON specification
我尝试查询不同的BSON元素类型,发现我的null表示为BSON元素类型6(未定义,不建议使用),而不是预期的BSON元素类型10(空).
I tried to query for the different BSON element types and found that my null was represented as a BSON element type 6 (undefined, deprecated) instead of the expected BSON element type 10 (null).
db.collection.find({ field: { "$type" : 6} };
这篇关于具有空值的MongoDB查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!