当前位置:网站首页>Mongodb - Introduction to the use of $exists and the combination of $ne, $nin, $nor, $not in query statements
Mongodb - Introduction to the use of $exists and the combination of $ne, $nin, $nor, $not in query statements
2022-07-23 22:37:00 【Growth path of Xiaobo test】
Come and learn today mongodb Usage of some other query statements in , It mainly contains the following contents :
1、$exists: Query whether a field exists
because mongodb It's a non relational database , therefore , Each record may contain different fields , There may be some fields between different data that have no written values , When you want to filter whether a field exists , You can use $exists To screen .
such as : Screening user Presence in table age Field records :
db.getCollection("user").find({age:{$exists:1}})
db.getCollection("user").find({age:{$exists:true}})
Screening user There is no age Field records :
db.getCollection("user").find({age:{$exists:0}})
db.getCollection("user").find({age:{$exists:false}})
2、 take $exists coordination $ne、$nin、$nor、$not Use
The individual use of each query condition may have been mastered , But when used together , You also need to master . Like you may have learned a lot of skills , But if you don't know how to master these skills , There is still room for improvement .
So let's see take $exists coordination $ne、$nin、$nor、$not Using the demonstration :
Inquire about user surface name Field equals “ Test Xiaobo ”, also name Records where fields exist :
db.getCollection("user").find({name:{$ne:" Test Xiaobo ",$exists:true}}) Inquire about user surface age Field not in xxx And age Records where fields exist :
db.getCollection("user").find({age:{$nin:[18,45,70],$exists:true}}) Inquire about user surface age Greater than or equal to 45 Or is it sex Records with empty fields :
db.getCollection("user").find({ $nor:[{age:{$lt:45},sex:{$exists:1}}] })Inquire about user surface age It's not equal to 45 also age Records where fields exist :
db.getCollection("user").find({ age:{$not:{$eq:45},$exists:1 } })These similar usages above , Sometimes it can help us quickly filter out some abnormal dirty data .
If it helps you , Remember forward 、 Leaving a message. 、 give the thumbs-up 、 Pay more attention to Oh !
If you are confused about your current job , I don't know how to improve myself , You can see : Career masters will help you with your interview and job search + Occupation development
END

All original articles
The official account is issued at the first time. 「 Xiaobo's road to growth 」

Long press QR code / Wechat code scanning Add the author
Previous recommendation
MongoDB-MongoDB brief introduction
MongoDB- adopt docker Set up a practice mongodb database
MongoDB- stay windows Install one locally on the computer mongodb The database of
MongoDB- Use mongo/mongosh Command line connection to database
MongoDB- Quick start MongoDB Some simple operations on the command line
MongoDB-_id Introduction to the meaning of fields
MongoDB- insert data insert、insertOne、insertMany、save Usage introduction
MongoDB- Introduction to the basic usage of table data query
MongoDB- In the query statement >、>=、<、<=、=、!=、in、not in Usage introduction
MongoDB- Logical operators in query statements not、and、or、nor Usage introduction
边栏推荐
- Linked list - 203. remove linked list elements
- El select drop-down box multi selection remote search anti display
- 作为开发,你不得不知道的三个性能测试工具|Jmeter、Apipost、JMH使用指南
- Cookies and sessions
- What are the product life cycle, common project functions, and information flow
- STM32单片机使用ADC功能驱动手指检测心跳模块
- Yuanqi Digitalization: existing mode or open source innovation Lixia action
- The font of Siyuan notes is thinner and lighter than that in other editors (atom, VSC, sublime)
- 【Matplotlib绘图】
- 视频号加强打击低俗内容:对违背公序良俗的内容必须赶尽杀绝
猜你喜欢

ONEFLOW V0.8.0 officially released

多线程问题:为什么不应该使用多线程读写同一个socket连接?
![[C language] address book (static version)](/img/bc/655c1176e11f66fd168c3fae01bb11.png)
[C language] address book (static version)

海外资深玩家的投资建议(3) 2021-05-04

What else do entrepreneurs need besides money? Exclusive interview with Mingyue Lake venture capital institutions

Storage structure and management disk. It's a bit like installing Win98. You need to partition and format the hard disk first

使用itextpdf提取PDF文件中的任意页码

【golang学习笔记】包(package)的使用

el-select下拉框多选远程搜索反显

I, AI doctoral student, online crowdfunding research topic
随机推荐
除了钱,创业者还需要什么?专访明月湖创赛创投机构
Stm32+esp8266+mqtt protocol connects Alibaba cloud Internet of things platform
众邦科技又一潜心力作 —— 陀螺匠 OA 系统
zk 是如何解决脑裂问题的
Is Ping An Securities' low commission account opening link safe? How to handle low commission
关于电脑端同步到手机端数据
Introduction to I2C Principle & Application of esp32
小说里的编程 【连载之十八】元宇宙里月亮弯弯
121. The best time to buy and sell stocks
As a developer, you have to know the three performance testing tools JMeter, API and jmh user guide
DeFi項目的盈利邏輯 2021-04-26
[acwing] weekly competition
MySQL索引事务
synthesizable之Verilog可不可综合
Array -- 27. remove elements
[jailhouse article] a novel software architecture for mixed criticality systems (2020)
Record the process of the first excavation and intersection
$, $*, [email protected], $$ Understand the meaning of 0
Programming in the novel [serial 16] the moon bends in the yuan universe
思源笔记的字体比其他的编辑器(Atom,VSC,sublime)内字体渲染更细更淡