我正在扩展在this example提供的解决方案,其中我在运算符$map的"in"中添加多个条件.所有条件都必须为真,所以我使用$AND运算符来组合它们.新条件判断文档中是否存在作为关键字的特定字段.我正在用$exists号接线员判断这个.用于判断此条件的代码片段如下
{
"isTypePattern": {
$exists: false
}
}
其中,(判断是否存在)字段的名称为:isTypePattern. 但是,当嵌入到$map操作符下时,该代码段将独立工作,并引发编译错误:
代码如下所示,下面是playground link:
db.collection.find({
"$expr": {
"$anyElementTrue": {
"$map": {
"input": "$entities",
"in": {
$and: [
{
"$regexMatch": {
"input": "Room1",
"regex": "$$this.id",
"options": "i"
},
},
{
"isTypePattern": {
$exists: false
}
}
]
}
}
}
}
})
因此,如果有人可以建议如何在$map运算符中嵌入$Existes,那就太好了