当前位置:网站首页>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边栏推荐
- 全栈开发提效神器——ApiFox(Postman + Swagger + Mock + JMeter)
- npm install报错 强制安装
- 2022.07.03 (lc_6111_counts the number of ways to place houses)
- 有哪些收益稳定的理财产品,这两个都不错
- SAP UI5 应用开发教程之一百零六 - 如何提高 SAP UI5 应用路由 url 的可读性试读版
- 107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍
- Hisilicon 3559 universal platform construction: YUV422 pit stepping record
- SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤
- Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
- 【C】 (written examination questions) pointer and array, pointer
猜你喜欢
NPM install error forced installation
【selenium自动化】常用注解
pycharm专业版下载安装教程
大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+
User login function: simple but difficult
Safety learning week4
Netcore3.1 JSON web token Middleware
What you learned in the eleventh week
Binary conversion problem
Huawei employs millions of data governance experts! The 100 billion market behind it deserves attention
随机推荐
有哪些收益稳定的理财产品,这两个都不错
Parameter passing mechanism of member methods
Parsing of XML
Expose testing outsourcing companies. You may have heard such a voice about outsourcing
SAP UI5 应用开发教程之一百零六 - 如何提高 SAP UI5 应用路由 url 的可读性试读版
The difference between string STR and new string
Hologres Query管理及超时处理
Liangzai's first program life and annual summary in 2022
[circuit design] optocoupler use and circuit design summary
Is it safe to open an account in the College of Finance and economics? How to open an account?
The most complete regular practical guide of the whole network. You're welcome to take it away
Relationship between classes and objects
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
||Interview questions you will encounter
26.2 billion! These universities in Guangdong Province have received heavy support
Innovation leads the direction. Huawei Smart Life launches new products in the whole scene
GDB常用命令
【C】 (written examination questions) pointer and array, pointer
107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍
各大主流编程语言性能PK,结果出乎意料