当前位置:网站首页>MongoDB-查询语句中逻辑运算符not、and、or、nor用法介绍
MongoDB-查询语句中逻辑运算符not、and、or、nor用法介绍
2022-07-23 19:02:00 【小博测试成长之路】
今天来学习在mongodb中的一些其他查询语句的用法,主要包含以下内容:
1、逻辑运算符$not
比如:查询user表age不为18的数据:
db.user.find({age:{$ne:18}})
db.user.find({age:{$not:{$eq:18}}})注意:如果需要查询的字段不存在, 也会算作条件成立
2、逻辑运算符$and
比如查询user表name为“小博”,并且age为17的数据
db.user.find({name:"小博",age:17})
db.user.find({$and:[{name:"小博"},{age:17}]})注意: $and后面必须对应一个数组格式,否则会报错:

3、逻辑运算符$or
比如查询user表中name为“小博”或者“测试小博”的数据:
db.user.find({name:{$in:['小博','测试小博']}})
db.user.find({$or:[{name:{$eq:'小博'}},{name:{$eq:'测试小博'}}]})
db.user.find({$or:[{name:'小博'},{name:'测试小博'}]})4、逻辑运算符$nor
针对前面的$and、$or、$not的用法,大家可能见到过,但对于$nor操作,可能见的少一点,$nor简单的理解就是:多个条件中不满足其中的某一个。
比如查询name不为“小博”或者“测试小博”的数据:
db.user.find({name:{$nin:['小博','测试小博']}})
db.user.find({$nor:[{name:'小博'},{name:'测试小博'}]})注意:如果需要查询的字段不存在, 也会算作条件成立

如果文章对你有帮助,记得转发、留言、点赞、加关注哦!
如果你对目前的工作比较困惑,不知道如何去提升自己,可以了解一下:职场大咖带你助攻面试求职+职业发展
END

所有原创文章
第一时间发布至此公众号「小博测试成长之路」

长按二维码/微信扫码 添加作者
边栏推荐
- Redis坏了怎么办?
- task03笔记2
- Leetcode - the nearest sum of three numbers
- 2022山东养老展,中国国际养老服务业展览会,济南老龄产业展
- 20. Ref and props
- Cannot read properties of null (reading ‘pickAlgorithm‘)
- Energy principle and variational method note 12: minimum potential energy principle
- Leetcode 238. product of arrays other than itself
- 百度地图数据可视化
- AtCoder B - Pizza
猜你喜欢

Principe de l'énergie et méthode variationnelle note 19: principe de l'énergie résiduelle minimale + principe du travail possible

Leetcode 152. product maximum subarray (brute force cracking can actually pass!)

搭建自己的目标检测环境,模型配置,数据配置 MMdetection

Hongke dry goods | teaches you how to parse floating-point data in MODBUS

phar反序列化

MySQL data recovery - using the data directory

Energy principle and variational method note 14: summary + problem solving

能量原理与变分法笔记16:虚位移原理的求解

2022DASCTF MAY

Leetcode 238. 除自身以外数组的乘积
随机推荐
Mecol Studio - Little Bear Development Notes 3
Leetcode 238. product of arrays other than itself
17.生命周期
R language uses the gather function of tidyr package to convert a wide table to a long table (wide table to long table), the first parameter specifies the name of the new data column generated from th
Leetcode 228. 汇总区间(可以,已解决)
Leetcode 216. combined sum III
Typescript use of new data type symbol
Redux summation case explanation version tutorial
Relevant interfaces of [asp.net core] option mode
Construction deployment scheme of GPS Beidou clock server (NTP network clock system)
重装系统后故障(报错:reboot and select proper boot deviceor insert boot media in selected boot device)
安装Win11找不到固态硬盘如何解决?
2022山东老博会,山东养老展,中国国际养老服务业展9月举办
scanf()和getchar()的用法讨论
What antenna is used for ant interface_ There is an interface at the back of the TV that says standard ant 75 Euro input. What does it mean, antenna? Can you connect the closed route "Suggested collec
【Unity项目实践】关卡解锁
Leetcode 152. product maximum subarray (brute force cracking can actually pass!)
攻防世界web题-fakebook
Debian | Can’t locate Debian/Debhelper/Sequence/germinate.pm in @INC
Attack and defense world web question Fakebook