具有空值的 MongoDB 查询 [英] MongoDB queries with null value

查看:33
本文介绍了具有空值的 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

我尝试查询不同的 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 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆