具有空值的MongoDB查询

编程入门 行业动态 更新时间:2024-10-27 12:33:48
本文介绍了具有空值的MongoDB查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的收藏集(MongoDB v 2.0.2)具有以下记录:

My collection (MongoDB v 2.0.2) has following records:

dbanization.find({}) { "_id" : 1001, "path" : [ ], "parent" : null } { "_id" : 1002, "path" : [ 1001 ], "parent" : NumberLong(1001) }

organization具有索引:

dbanization.ensureIndex({"path":1}); dbanization.ensureIndex({"parent":1},{sparse:false});

(请注意,我输入了awarnes sparse : false-授予对null进行索引) 但是,执行:

(note I put awarnes sparse : false - to grant that null is indexed) But, executing:

dbanization.find({"parent":null})

返回空集.怎么了?预先谢谢你

Returns empty set. What is wrong? Thank you in advance

推荐答案

我遇到了同样的问题.阅读以下文档后

I had the same issue. After reading the following documents

  • 查询和空值
  • BSON规范
  • 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查询

本文发布于:2023-11-05 19:45:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!