mongodb中find $ne null 与$exists的区别
$ne null 会把空列表也算入,即使不存在。
$exists 的识别效果就比较好
1.插入样例数据
db.nullexistsdemo.insertMany( [{ "name" : "wqbin", "desc" : [ ] }
,{ "name" : "wang", "desc" : { } }
,{ "name" : "quincy", "desc" : { "job" : "coder", "degree" : 4 } }
,{ "name" : "wangyang"}]
)

2.查看不等于null的数值
db.nullexistsdemo.find({"desc.job":{"$ne":null}})

db.nullexistsdemo.find({"desc.degree":{"$ne":null}})

3.查看等于null的数值
db.nullexistsdemo.find({"desc.degree":{"$eq":null}})
db.nullexistsdemo.find({"desc.job":{"$eq":null}})

4.查看不exists的数据
db.nullexistsdemo.find({"desc.degree":{"$exists":null}})
db.nullexistsdemo.find({"desc.job":{"$exists":false}})

5.查看exists的数据
db.nullexistsdemo.find({"desc.degree":{"$exists":1}})
db.nullexistsdemo.find({"desc.job":{"$exists":""}})
db.nullexistsdemo.find({"desc.job":{"$exists":true}})

mongodb中find $ne null 与$exists的区别的更多相关文章
- SQL 查询中not in 与 not exists 的区别
1.in和exists in是把外表和内表作hash连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询,一直以来认为exists比in效率高的说法是不准确的.如果查询的两个表 ...
- js中NAN、NULL、undefined的区别
NaN:保留字(表明数据类型不是数字) undefined:对象属性或方法不存在,或声明了变量但从未赋值.即当你使用了对象未定的属性或者未定义的方法时或当你声明一个变量,但你确从未对其进行赋值,便对其 ...
- php中0,空,null和false的区别
<? $str1 = null; $str2 = false; echo $str1==$str2 ? ‘相等’ : ‘不相等’; $str3 = ""; $str4 = 0 ...
- Javascript中NaN、null和undefinded的区别
var a1; var a2 = true; var a3 = 1; var a4 = "Hello"; var a5 = new Object(); var a6 = null; ...
- php中0,空,null和false之间区别
$a = 0; $b="0"; $c= ''; $d= null; $e = false; echo "5个变量-原始测试类型"; var_dump($a);/ ...
- 在MongoDB中执行查询、创建索引
1. MongoDB中数据查询的方法 (1)find函数的使用: (2)条件操作符: (3)distinct找出给定键所有不同的值: (4)group分组: (5)游标: (6)存储过程. 文档查找 ...
- MongoDB中常用的find
接着前一篇文章,下面主要介绍一下MongoDB中常用的find操作. 先打开MongoDB shell,通过下面一组命令插入一些数据. post1 = {} post2 = {} post3 = {} ...
- 在MongoDB中执行查询与创建索引
实验目的: (1)掌握MongoDB中数据查询的方法: (2)掌握MongoDB中索引及其创建: 实验内容: 一. MongoDB中数据查询的方法: (1)find函数的使用: (2)条件操作符: a ...
- 详解MongoDB中的多表关联查询($lookup)
一. 聚合框架 聚合框架是MongoDB的高级查询语言,它允许我们通过转换和合并多个文档中的数据来生成新的单个文档中不存在的信息. 聚合管道操作主要包含下面几个部分: 命令 功能描述 $projec ...
随机推荐
- 自定义Hive函数
7. 函数 7.1 系统内置函数 查看系统自带的函数:show functions; 显示自带的函数的用法:desc function upper(函数名); 详细显示自带的函数的用法:desc fu ...
- LeetCode 15. 三数之和(3Sum)
15. 三数之和 15. 3Sum 题目描述 Given an array nums of n integers, are there elements a, b, c in nums such th ...
- MVC-初识
RAZOR视图介绍 一个cshtml,主体是一个html文本,里面可以写前台和后台代码,混合编写(个人认为不太好,应该分离),这个文件最后会被会被编译为一个类(所以他可以像类一样写一些方法,其他的地方 ...
- 【坑】使用IDEA创建maven的时候,提示缺少plugin-clean 等
解决方法 检查你的网络,能否访问 maven 中央仓库 : 在 IDEA 中是否对 maven 进行了配置 IDEA 默认使用的 仓库 和 配置文件,都是 .m2 下面的: 如果你自己对 maven ...
- VS2010 安装boost库
1.下载boost库 boost官网:www.boost.org,目前最新的版本是1.64,直接下载地址:https://dl.bintray.com/boostorg/release/1.64.0/ ...
- COleVariant类
COleVariant本质上是一个枚举,用同一种类型来表达不同的子类型.如同boost中的variant. COLeVariant类是对VARIANT结构的封装. VARIANT结构包含两部分.其一是 ...
- Navicat连接Oracle数据库用户权限问题
解决Navicat连接Oracle数据库用户权限问题: 第一步:在cmd窗口运行[sqlplus], 第二步:输入Oracle的用户名和口令连接Oracle数据库, 第三步:执行授权代码,给用户授予D ...
- Django查找数据库objects.filter() 排序order_by Q()与或非 F()属性之间比较 聚合函数的用法
条件选取QuerySet的时候,filter表示=参数可以写查询条件,exclude表示!=,querySet.distinct() 去重复(除了get返回值都是QuerySet,可以继续调用所有函数 ...
- 回归损失函数:L1,L2,Huber,Log-Cosh,Quantile Loss
回归损失函数:L1,L2,Huber,Log-Cosh,Quantile Loss 2019-06-04 20:09:34 clover_my 阅读数 430更多 分类专栏: 阅读笔记 版权声明: ...
- Java非常好用的反射框架Reflections
MAVEN 坐标 <dependency> <groupId>org.reflections</groupId> <artifactId>reflect ...