当前位置:网站首页>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边栏推荐
- 大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+
- College degree, what about 33 year old Baoma? I still sell and test, and my monthly income is 13K+
- 【C】 (written examination questions) pointer and array, pointer
- P4281 [AHOI2008]紧急集合 / 聚会(LCA)
- Maximum number of "balloons"
- 2022.07.03 (lc_6111_counts the number of ways to place houses)
- Operator explanation
- MySQL uses the explain tool to view the execution plan
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- js如何实现数组转树
猜你喜欢

【C】(笔试题)指针与数组,指针

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

“薪資倒掛”、“畢業生平替” 這些現象說明測試行業已經...

SAP ui5 application development tutorial 106 - how to improve the readability of SAP ui5 application routing URL trial version

4. Scala writes HelloWorld in idea, in-depth analysis of accompanying objects, and association of source packages

潘多拉 IOT 开发板学习(RT-Thread)—— 实验4 蜂鸣器+马达实验【按键外部中断】(学习笔记)

两个数相互替换

"Upside down salary", "equal replacement of graduates" these phenomena show that the testing industry has

Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement
Date time type and format in MySQL
随机推荐
[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
Visual explanation of Newton iteration method
Consolidated expression C case simple variable operation
Learning of basic amplification circuit
Kibana index, mapping, document operation
abc 258 G - Triangle(bitset)
Several simplified forms of lambda expression
Getting started with Paxos
Binary conversion problem
leetcode518,377
What happened to those who focused on automated testing?
GDB common commands
Summer challenge brings you to play harmoniyos multi terminal piano performance
107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
[circuit design] optocoupler use and circuit design summary
Two numbers replace each other
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
Deux nombres se remplacent
URL和URI