当前位置:网站首页>Query for Boolean field as "not true" (e.g. either false or non-existent)
Query for Boolean field as "not true" (e.g. either false or non-existent)
2022-07-05 00:49:00 【Superior virtue and weak water】
problem :
I'm sure I'm missing something very basic in MongoDB queries, can't seem to get this simple condition. I'm sure I'm MongoDB Some very basic things are missing from the query , It seems impossible to obtain such a simple condition .
Consider this collection Consider this set
> db.tests.find(){ "_id" : ObjectId("..."), "name" : "Test1" , "deleted" : true}{ "_id" : ObjectId("..."), "name" : "Test2" , "deleted" : false}{ "_id" : ObjectId("..."), "name" : "Test3" }
I would simply like to query all the items that are "not deleted" I just want to check all “ Not delete ” Project
I know how to find the item that has a "deleted" flag set to true: I know how to find “ deleted ” Flag set to true Project :
> db.tests.find({deleted:true}){ "_id" : ObjectId("..."), "name" : "Test1" , "deleted" : true}
But how do I find all items that are NOT "deleted"
(eg negate the above query, or in other words, any items that either doesn't have a "deleted"
field, or have it with value false
But how did I find out , Are all the projects "deleted"
( For example, deny the above query , Or to put it another way , Without any items "deleted"
field , Or value has it false
What I tried by guessing (please don't laugh...) What do I guess ( Please don't laugh ......)
> db.tests.find({$not : {deleted: true}})
(returns no results)( No results returned )
> db.tests.find({$not : {$eq:{deleted:true}}})
error: { "$err" : "invalid operator: $eq", "code" : 10068 } error :{“$ err”:“ Invalid operator :$ eq”,“code”:10068}
> db.tests.find({deleted:{$not: true}})
error: { "$err" : "invalid use of $not", "code" : 13041 } error :{“$ err”:“ Invalid use $ not”,“ Code ”:13041}
> db.tests.find({deleted:{$not: {$eq:true}}})
error: { "$err" : "invalid use of $not", "code" : 13034 } error :{“$ err”:“ Invalid use $ not”,“ Code ”:13034}
What am I missing? What I missed ?
Solution :
Reference resources : https://stackoom.com/en/question/1H2UQ边栏推荐
- Oracle case: SMON rollback exception causes instance crash
- ORB(Oriented FAST and Rotated BRIEF)
- Acwing164. Accessibility Statistics (topological sorting +bitset)
- PyTorch: In-place Operation
- 6. Scala operator
- [selenium automation] common notes
- ||Interview questions you will encounter
- Consolidated expression C case simple variable operation
- Maximum number of "balloons"
- 创新引领方向 华为智慧生活全场景新品齐发
猜你喜欢
程序员SQL数据脚本编码能力弱,BI做不出来怎么办?
Date time type and format in MySQL
Detailed explanation of openharmony resource management
Oracle case: SMON rollback exception causes instance crash
Recursive execution mechanism
SAP UI5 应用开发教程之一百零六 - 如何提高 SAP UI5 应用路由 url 的可读性试读版
Visual explanation of Newton iteration method
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
Safety learning week4
每日刷题记录 (十三)
随机推荐
Expose testing outsourcing companies. You may have heard such a voice about outsourcing
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
skimage: imread & imsave & imshow
Liangzai's first program life and annual summary in 2022
Detailed explanation of multi-mode input event distribution mechanism
(脚本)一键部署redis任意版本 —— 筑梦之路
【C】(笔试题)指针与数组,指针
Is it safe to open an account in the College of Finance and economics? How to open an account?
ORB(Oriented FAST and Rotated BRIEF)
Distributed base theory
Daily practice (18): stack containing min function
Multilingual Wikipedia website source code development part II
uniapp上传头像
Complete knapsack problem (template)
Kibana index, mapping, document operation
Sorting selection sorting
Deux nombres se remplacent
[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
TS快速入门-函数
107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍