当前位置:网站首页>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
边栏推荐
- 使用itextpdf提取PDF文件中的任意页码
- Matlab wavelet toolbox import signal error (doesn't contain one dimensional single)
- [unity3d daily bug] unity3d solves "the type or namespace name" XXX "cannot be found (are you missing the using directive or assembly reference?)" Etc
- Programmation JDBC pour MySQL
- Linked list - 203. remove linked list elements
- Array - 11. Containers with the most water
- 小说里的编程 【连载之十七】元宇宙里月亮弯弯
- 小说里的编程 【连载之十九】元宇宙里月亮弯弯
- Preliminary discussion on POC compilation
- STM32 MCU uses ADC function to drive finger heartbeat detection module
猜你喜欢

Rails with OSS best practices

torchvision.datasets.ImageFolder前的数据整理及使用方法

STM32+ESP8266+MQTT协议连接阿里云物联网平台
About synchronizing data from computer to mobile

Investment suggestions for overseas senior players (3) 2021-05-04

多线程问题:为什么不应该使用多线程读写同一个socket连接?

Profit logic of DFI project 2021-04-26

ospf终极实验——学会ospf世纪模板例题

Matlab wavelet toolbox import signal error (doesn't contain one dimensional single)

ADB 命令结合 monkey 的简单使用,超详细
随机推荐
The simple use of ADB command combined with monkey is super detailed
[jailhouse article] a novel software architecture for mixed criticality systems (2020)
巴菲特股东大会的启示 2021-05-06
Life always needs a little passion
10 basic written interview questions, how many questions can you answer?
Array - 704. Binary search
狂神redis笔记10
Inspiration from Buffett's shareholders' meeting 2021-05-06
vip股票账户在手机开通安全吗?
【golang学习笔记】flag包的简单使用,命令行解析
Sudoku written for once and for all
关于电脑端同步到手机端数据
Record the process of the first excavation and intersection
How to add an operator in ONEFLOW
激光雷达点云数据录制的rosbag文件转换成csv文件
怎么开户买收益百分之六的理财产品呢?
Rosbag file recorded by LIDAR point cloud data is converted into CSV file
openEuler 资源利用率提升之道 01:概论
What are the product life cycle, common project functions, and information flow
ES6箭頭函數的使用