当前位置:网站首页>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
边栏推荐
猜你喜欢

The ultimate experiment of OSPF -- learn the example of OSPF century template

LeetCode高频题62. 不同路径:机器人从左上角到右下角的路径有多少条?纯概率排列组合问题,而不是动态规划题

Yuanqi Digitalization: existing mode or open source innovation Lixia action

DeFi项目的盈利逻辑 2021-04-26

Rails搭配OSS最佳实践

How to reasonably estimate the size of thread pool

10道面试基础笔试题,你能对几题?

Preliminary discussion on POC compilation

MySQL index transaction

El select drop-down box multi selection remote search anti display
随机推荐
LeetCode高频题53. 最大子数组和,具有最大和的连续子数组,返回其最大和
STM32+ESP8266+MQTT协议连接阿里云物联网平台
Rosbag file recorded by LIDAR point cloud data is converted into CSV file
小说里的编程 【连载之二十】元宇宙里月亮弯弯
Investment suggestions for overseas senior players (2) 2021-05-03
openEuler 资源利用率提升之道 01:概论
Neo4j application
How to completely force the killing of background unrelated processes?
多线程问题:为什么不应该使用多线程读写同一个socket连接?
[golang learning notes] is parameter transfer in go language value transfer or reference transfer
vip股票账户在手机开通安全吗?
作为开发,你不得不知道的三个性能测试工具|Jmeter、Apipost、JMH使用指南
DeFi项目的盈利逻辑 2021-04-26
疯狂的牛市,下半场何去何从?2021-04-30
How can I open an account to buy financial products with a 6% income?
Life always needs a little passion
Is it safe to open a VIP stock account on your mobile phone?
zk 是如何解决脑裂问题的
Programming in the novel [serial 20] the moon bends in the yuan universe
海外资深玩家的投资建议(2) 2021-05-03