1 插入数据

db.inventory.insertMany([
{ _id: 1, item: null },
{ _id: 2 }
])

2 查询null值

db.inventory.find({itme:null})

如果要精确查找到对应的null的字段,应该

db.inventory.find({item:{$type:10}})

3 查询是否存在这个元素

db.inventory.find({item:{$exists:false}})

Different query operators in MongoDB treat null values differently.

This page provides examples of operations that query for null values using the db.collection.find()method in the mongo shell. The examples on this page use the inventory collection. To populate theinventory collection, run the following:

 
Copy
db.inventory.insertMany([
{ _id: 1, item: null },
{ _id: 2 }
])

You can run the operation in the web shell below:

Equality Filter

The { item : null } query matches documents that either contain the item field whose value is null orthat do not contain the item field.

For example, the following query returns both documents:

Copy
db.inventory.find( { item: null } )

Type Check

The { item : { $type: 10 } } query matches documents that contains the item field whose value isnull only; i.e. the value of the item field is of BSON Type Null (i.e. 10) :

Copy
db.inventory.find( { item : { $type: 10 } } )

The query returns only the document where the item field has a null value.

Existence Check

The { item : { $exists: false } } query matches documents that do not contain the item field:

Copy
db.inventory.find( { item : { $exists: false } } )

The query returns only the document that does not contain the item field:

SEE ALSO

The reference documentation for the $type and $exists operators.

13.Query for Null or Missing Fields-官方文档摘录的更多相关文章

  1. Cocos Creator 加载和切换场景(官方文档摘录)

    Cocos Creator 加载和切换场景(官方文档摘录) 在 Cocos Creator 中,我们使用场景文件名( 可以不包含扩展名)来索引指代场景.并通过以下接口进行加载和切换操作: cc.dir ...

  2. ng的概念层次(官方文档摘录)

    官方文档是这么说的: You write Angular applications by: composing HTML templates with Angularized markup, writ ...

  3. MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields

    Different query operators in MongoDB treat null values differently. The examples on this page use th ...

  4. Cocos Creator 生命周期回调(官方文档摘录)

    Cocos Creator 为组件脚本提供了生命周期的回调函数.用户通过定义特定的函数回调在特定的时期编写相关 脚本.目前提供给用户的声明周期回调函数有: onLoad start update la ...

  5. Cocos Creator 使用计时器(官方文档摘录)

    在 Cocos Creator 中,我们为组件提供了方便的计时器,这个计时器源自于 Cocos2d-x 中的 cc.Scheduler,我们将它保留在了 Cocos Creator 中并适配了基于组件 ...

  6. angular 模板语法(官方文档摘录)

    https://angular.cn/guide/template-syntax {{}} 和"" 如果嵌套,{{}}里面求完值,""就是原意 <h3&g ...

  7. 8.Query Documents-官方文档摘录

    总结 1 先插入数据 db.inventory.insertMany([ { item: "journal", qty: 25, size: { h: 14, w: 21, uom ...

  8. bootstrap课程13 bootstrap的官方文档中有一些控件的使用有bug,如何解决这个问题

    bootstrap课程13  bootstrap的官方文档中有一些控件的使用有bug,如何解决这个问题 一.总结 一句话总结:因为演示是正常的,所以检查演示效果的代码,把那一段相关的都弄过来就可以了 ...

  9. Elasticsearch 7.4.0官方文档操作

    官方文档地址 https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html 1.0.0 设置Elasticsea ...

随机推荐

  1. ar命令学习

    之前,学习Linux下使用静态库的时候涉及到了这三个命令: gcc -c my_strcpy.c my_strcmp.car rcs libmylib.a *.ogcc -o main main.c ...

  2. markdown 表格宽度调整

    先在浏览器中看看 HTML是怎样的:   看起来似乎不错.回到 Markdown 上,在原表格前添加 CSS 代码,类似这样: <style> table th:first-of-type ...

  3. etl工具,kettle实现循环

    Kettle是一款国外开源的ETL工具,纯Java编写,可以在Window.Linux.Unix上运行,绿色无需安装,数据抽取高效稳定. 业务模型: 在关系型数据库中有张很大的数据存储表,被设计成奇偶 ...

  4. josn 格式 解析

    格式为:{"lng":113.534634,"lat":22.274308} 解析步骤如下: <?php $a=json_decode($goods_in ...

  5. UCASE() 函数

    UCASE() 函数 UCASE 函数把字段的值转换为大写. SQL UCASE() 语法 SELECT UCASE(column_name) FROM table_name

  6. AWS系列-S3实现文件服务页面展示

    最近由于业务需求,对于备份的数据存放到S3上面,并需要页面展示.而且还能下载. 把这个桶里面的对象,都在某个静态页面展示.并且 我可以把这个对象下载下来. 首页内容就是 桶里面的对象. 并且可以随时查 ...

  7. 分页技巧_抽取出公共的分页用的Service方法

    分页技巧_抽取出公共的分页用的Service方法 TopicAction.java ForumAction.java 放在父类中DaoSupport.java DaoSupportImpl.java ...

  8. Spring_day04--整合struts2和spring框架

    整合struts2和spring框架 1 把struts2的action交给spring管理 2 实现过程 第一步 导入struts2和spring的jar包 (1)导入用于整合的jar包 第二步 创 ...

  9. Hadoop1.2.1 伪分布式安装

    Hadoop1.2.1 单机模式安装 Hadoop组件依赖图(从下往上看) 安装步骤: 详细步骤: 设置ssh自动登录(如下图): 1.输入命令 [ssh-keygen -t rsa],然后一直按回车 ...

  10. WPS长文档编辑技巧之二:对样式的设置与修改

    目录:       1.使用系统内置样式 2.如何修改样式 3.如何自定义样式 4.在文档使用多级编号 5.结合样式编辑文档大纲 6.利用文档结构图查看大纲结构 正文: 1.使用系统内置样式 在使用样 ...