gpt4 book ai didi

node.js - 为什么我不能在 Mongo 管道匹配中使用 $nin、$exists 等?

转载 作者:可可西里 更新时间:2023-11-01 10:08:59 25 4
gpt4 key购买 nike

我对这个答案进行了高估和低估,但没有任何效果。我有一个管道查询,其匹配项如下:

$match: {
$expr: {
$and: [
....
]
}
}

在 $and 中,我有各种使用 $eq、$in、$ne、$gt、$lt 等的条件。

然而,尽管我尽我所能,但我无法让它识别 $nin 或 $exists。我试图在搜索不存在的 key 时添加一个术语,例如:

{ $exists: [ '$key', 0 ] }

我不断得到

MongoError: Unrecognized expression '$exists'

MongoError: Unrecognized expression '$nin'

有人能帮忙吗??

最佳答案

您只能在 $expr 中使用 聚合 运算符和 $nin$exists查询运算符不是聚合运算符。在$expr之外使用以上条件表达。

有点像

{ "$match": {
"key": { "$exists": true },
"$expr": {
"$and": [
{...}, {...}
]
}
}}

关于node.js - 为什么我不能在 Mongo 管道匹配中使用 $nin、$exists 等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53504500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com