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. 改进cocos2dx中lua读ccb的方法

    cocos2dx自带的CCBProxy真弱,还好提供了一个CCBReaderLoader.lua,但是也不好用, 于是修改了一下CCBReaderLoader,下面直接贴代码了. function N ...

  2. [内核]Linux UserSpace和Kernel之间如何联系

    转自:http://blog.csdn.net/dreaming_my_dreams/article/details/8272586 应用层和驱动的衔接,一直是一个老大难问题,若弄不清楚,总觉得驱动写 ...

  3. senfile函数实例的运行过程截图

    //要传输的文件内容如下所示: 启动服务器,等待客户端连接(在同一台主机上模拟的) 客户端远程登录,这里是在本地登录 这个要注意一点就是远程登陆的时候一定要带上端口号不然连接失败!!

  4. Spider Studio 新版本 (20131201) - BrowserManager / 节点选择器 / JQueryContext.Focus

    2013-12-1版本更新, 包含如下改动: 1. 修复BrowserManager重复初始化的bug; 2. 大幅提高节点选择器性能: 以网页 http://data.sports.sohu.com ...

  5. oozie客户端常用操作命令

    1.提交作业,作业进入PREP状态 oozie job -oozie http://localhost:11000/oozie -config job.properties -submit job: ...

  6. 树莓派安装centos 7系统

    1,格式化 https://www.sdcard.org/downloads/formatter_4/eula_windows/ 2,烧录,Win32DiskImager https://source ...

  7. 数据库 Navicat_Premium_11.0.10 破解版下载安装

    下载地址:http://www.liangchan.net/soft/download.asp?softid=4785&downid=8&id=4804 破解说明:安装之后不要立即启动 ...

  8. oracle起定时任务,每隔1秒执行一次

    创建一个测试表和一个存储过程: create table a(a date); create or replace procedure test as begin insert into a valu ...

  9. vue-cli打包构建时常见的报错解决方案

    报错1:vue-cli项目本地npm run dev启动后,chrome打开是空白页 解决方案:将config下的index.js中的assetsPublicPath路径都设置为‘/’绝对路径 报错2 ...

  10. Mac终端使用mysql

    1.安装完mysql后给mysql命别名 alias mysql=/usr/local/mysql/bin/mysql aliasmysqladmin=/usr/local/mysql/bin/mys ...