13.Query for Null or Missing Fields-官方文档摘录
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:
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:
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) :
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:
db.inventory.find( { item : { $exists: false } } )
The query returns only the document that does not contain the item field:
13.Query for Null or Missing Fields-官方文档摘录的更多相关文章
- Cocos Creator 加载和切换场景(官方文档摘录)
Cocos Creator 加载和切换场景(官方文档摘录) 在 Cocos Creator 中,我们使用场景文件名( 可以不包含扩展名)来索引指代场景.并通过以下接口进行加载和切换操作: cc.dir ...
- ng的概念层次(官方文档摘录)
官方文档是这么说的: You write Angular applications by: composing HTML templates with Angularized markup, writ ...
- 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 ...
- Cocos Creator 生命周期回调(官方文档摘录)
Cocos Creator 为组件脚本提供了生命周期的回调函数.用户通过定义特定的函数回调在特定的时期编写相关 脚本.目前提供给用户的声明周期回调函数有: onLoad start update la ...
- Cocos Creator 使用计时器(官方文档摘录)
在 Cocos Creator 中,我们为组件提供了方便的计时器,这个计时器源自于 Cocos2d-x 中的 cc.Scheduler,我们将它保留在了 Cocos Creator 中并适配了基于组件 ...
- angular 模板语法(官方文档摘录)
https://angular.cn/guide/template-syntax {{}} 和"" 如果嵌套,{{}}里面求完值,""就是原意 <h3&g ...
- 8.Query Documents-官方文档摘录
总结 1 先插入数据 db.inventory.insertMany([ { item: "journal", qty: 25, size: { h: 14, w: 21, uom ...
- bootstrap课程13 bootstrap的官方文档中有一些控件的使用有bug,如何解决这个问题
bootstrap课程13 bootstrap的官方文档中有一些控件的使用有bug,如何解决这个问题 一.总结 一句话总结:因为演示是正常的,所以检查演示效果的代码,把那一段相关的都弄过来就可以了 ...
- Elasticsearch 7.4.0官方文档操作
官方文档地址 https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html 1.0.0 设置Elasticsea ...
随机推荐
- jQuery——实现弹窗
window.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...
- 深入分析DDR(转载)
深入分析:我们为何需要DDR2内存技术 http://www.cnblogs.com/thx-bj/archive/2008/04/02/1134040.html 文/IT168评测室特约 Myddn ...
- 工作中Hadoop,Spark,Phoenix,Impala 集群中遇到坑及解决方案
1.HDFS 修复 问题描述:其他部门在yarn平台上跑spark 程序错误的生成了海量的不到100K的小文件,导致namenode压力过大,其中一个namenode宕机后,没有及时发现 使得edit ...
- mobile体验效果:增加点击后反馈
document.addEventListener("touchstart", function(){}, true) //JS部分 a:active{ background:re ...
- Softmax vs. Softmax-Loss VS cross-entropy损失函数 Numerical Stability(转载)
http://freemind.pluskid.org/machine-learning/softmax-vs-softmax-loss-numerical-stability/ 卷积神经网络系列之s ...
- ThinkPHP项目笔记之RBAC(权限)补充篇
这里,主要补充的是配置以及相关代码问题. <?php return array( //'配置项'=>'配置值' 'RBAC_SUPERADMIN' => 'admin',//超级管理 ...
- hdu 1140:War on Weather(计算几何,水题)
War on Weather Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- MP 及OMP算法解析
转载自http://blog.csdn.net/pi9nc/article/details/18655239 1,MP算法[盗用2] MP算法是一种贪心算法(greedy),每次迭代选取与当前样本残差 ...
- iOS开发之--去除按钮的点击效果
Button.adjustsImageWhenHighlighted = NO; 去除按钮的点击效果,用这句代码就可以了!
- vue向路由组件传递props
父子间的组件通讯是通过props和$emit来实现的,那么路由之间的通讯呢,往下看: 我现在再webpack里面有一个这样的结构, 我现在想test1里面的按钮点击跳转到test2里面,获得到test ...