当前位置:网站首页>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边栏推荐
- 有哪些收益稳定的理财产品,这两个都不错
- Multilingual Wikipedia website source code development part II
- JS how to realize array to tree
- Enterprise application business scenarios, function addition and modification of C source code
- Some basic functions of enterprise projects are developed, and important things are saved to online first a
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验4 蜂鸣器+马达实验【按键外部中断】(学习笔记)
- Identifiers and keywords
- [error reporting] "typeerror: cannot read properties of undefined (reading 'split')“
- Pycharm professional download and installation tutorial
- 【selenium自动化】常用注解
猜你喜欢
OpenHarmony资源管理详解
两个数相互替换
华为百万聘请数据治理专家!背后的千亿市场值得关注
What if the programmer's SQL data script coding ability is weak and Bi can't do it?
【C】 (written examination questions) pointer and array, pointer
It's too convenient. You can complete the code release and approval by nailing it!
Continuous modification of business scenario functions
"Upside down salary", "equal replacement of graduates" these phenomena show that the testing industry has
[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement
随机推荐
[STM32] (I) overview and GPIO introduction
Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)
Two numbers replace each other
[circuit design] optocoupler use and circuit design summary
【C】 (written examination questions) pointer and array, pointer
P3304 [sdoi2013] diameter (diameter of tree)
npm install报错 强制安装
URL和URI
Leetcode70 (Advanced), 322
Playwright之录制
海思3559万能平台搭建:YUV422的踩坑记录
实战模拟│JWT 登录认证
2022.07.03(LC_6108_解密消息)
Paxos 入门
Nine Qi single chip microcomputer ny8b062d single key control four LED States
Kibana index, mapping, document operation
Open3d uses GICP to register point clouds
Actual combat simulation │ JWT login authentication
Relationship between classes and objects
【C】(笔试题)指针与数组,指针