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. win7下如何显示缅文和使用缅文输入法?

    windows 7 操作系统默认不支持缅文,所以缅文在win7上不能显示,当然也没有提供缅文输入法. 一.显示缅文 windows系统下显示缅文字母只需要安装缅文字体就可以了.目前常见的缅文字体就是Z ...

  2. excel鼠标拖选慢shift选择快的问题

    今天遇到个惊天大坑,关于excel的,最近,一直在调查这个东西,刚开始真的是毫无头绪,反正现在就是excel的值的copy会偶尔慢,慢的情况也是不明白,就是稀里糊涂的调查. 刚开始连100%再现这个b ...

  3. PHP uxf framework 在模版中加入url标签

    1. 确保不修改discuz代码: 2. 继承discuz template类,重载parse_template 方法:由于discuz在模版引擎这一块没有考虑扩展性,对标签的解析全部写在一个方法中, ...

  4. openresty package.path require 报错

    在文件中 package.path = '/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;' packag ...

  5. 扩展-Easyui Datagrid相同连续列合并扩展(一)

    一.autoMergeCellAndCells实现效果 调用方法: function onLoadSuccess(data){     $(this).datagrid("autoMerge ...

  6. EasyUI 另一种form提交方式

    (function ($) { window.XW = {}; //全局系统对象 //异步请求统一调用方法 XW.ajax = function (options, param, callback) ...

  7. Jquery仿IGoogle实现可拖动窗口

    google可谓是ajax的特效用的淋漓尽致,google suggest, google map,igoogle 可拖动窗口等等...今天要做一个网站的类似效果,与编程人生的站长沟通了一下,仿照iG ...

  8. Unity5 AssetBundle打包加载及服务器加载

    Assetbundle为资源包不是资源 打包1:通过脚本指定打包 AssetBundleBuild ab = new AssetBundleBuild                         ...

  9. Administrator privileges required for OLE Remote Procedure Call debugging: this feature will not work..

    VC++ 6.0单步调试(F10)出现警告框: 解决方法: 右键VC++ 6.0程序图标

  10. hdu 1813(IDA*)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1813 思路:首先bfs预处理出‘0’到边界点最短距离,然后构造 h() 为所’0‘点逃离迷宫的最少步数 ...