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 ...
随机推荐
- ldap 使用 问题参考
Q2.ldapsearch查询一个有30000多条记录时出现:Size limit exceeded 4 A2:服务器端配置文件有sizelimit 1000的限制!用管理员身份查询-D"c ...
- 一款基于jQuery的超酷动画幻灯片
今天给大家带来一款仿步步高vivo手机网站的一款首页焦点幻灯展示特效,带有超酷炫的动画特效,动态效果丝毫不逊色于flash动画,具有很强的视觉冲击力,推荐下载学习! 提示:兼容360.FireFox. ...
- RP2837 OUT1-OUT2 对应关系 2路DO
RP2837 OUT1-OUT2 对应关系: OUT1 AD2 PD22 继电器1 OUT2 AD4 PD24 继电器2 root@sama5d3-linux:~ echo 11 ...
- time函数
time函数 time #include<time.h> time_t time(time_t *t); typdef long int time_t; time() returns th ...
- ssh2——Interceptor拦截器
尽管没学过struts1吧.可是了解到struts1中并没有拦截器, 到Struts2才有.它是基于WebWork发展起来的, 顾名思义,说到拦截器大家首先肯定会想到它是拦截东西的,起到一个限制的作 ...
- JQueryEasyUI-DataGrid显示数据,条件查询,排序及分页
<html><head> <title></title> <script src="/jquery-easyui-1.3.4 ...
- C#调用系统API
API简介 1) C#中的简单数据类型与API中的数据类型对应关系 2) 如何在调用API时传递复杂参数:封装类.结构和联合 3) 如何调用API 4) 如何确保成功调用API
- splash启动速度优化
在styles.xml中加入 <style name="AppSplash" parent="android:Theme"> <item na ...
- HDU 1284 钱币兑换问题(全然背包:入门题)
HDU 1284 钱币兑换问题(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1284 题意: 在一个国家仅有1分,2分.3分硬币,将钱N ( ...
- 剑指 offer set 20 打印出和为 s 的连续正序序列
题目 100 可以由 9~16, 或者 18 ~ 22 组成 思路 1. 与 Leetcode Container With Most Water 有些类似, 依然是平移题目. 但这道更加复杂 2. ...