我使用$纂操作:
{ $redact: {
$cond: {
"if": {
"$lt": [ "$number1", "$number2" ],
},
"then": "$$KEEP",
"else": "$$PRUNE"
}
}}
我想$and: [{$lt:["$number1, $number2"]}, {$exists:[$number3, 1]}]
,但我不能得到$存在,或者检查空。
我使用$纂操作:
{ $redact: {
$cond: {
"if": {
"$lt": [ "$number1", "$number2" ],
},
"then": "$$KEEP",
"else": "$$PRUNE"
}
}}
我想$and: [{$lt:["$number1, $number2"]}, {$exists:[$number3, 1]}]
,但我不能得到$存在,或者检查空。
你想$ifNull
,因为它是一个“之类的”同等学历,返回的替代值的附加功能,其中场不存在:
{ "$redact": {
"$cond": {
"if": {
"$and": [
{ "$lt": [ "$number1", "$number2" ] },
{ "$ifNull": [ "$number3", false ] }
]
},
"then": "$$KEEP",
"else": "$$PRUNE"
}
}}
那么,该领域存在的价值该字段被返回,并且这基本上与说true
(除非它的值实际上是false
,在这种情况下,换行为$cond
)基本相同,或者返回已经作为false
提供的替换。
只需使用'$ match' – Rohmer