预期为“ [”或AggregationStage,但找到“ {”。:MongoDB聚合不允许我在$ eq

我编写了一个包含以下代码的MongoDB管道:

  {
    $eq: [
      {
        "$toLower": "HELLO"
      },"hello"
    ]
  }

这是Mongo Compass中的屏幕截图

预期为“ [”或AggregationStage,但找到“ {”。:MongoDB聚合不允许我在$ eq

我希望它只返回true,然后“ $ match”所有(暂时)。 最终,我将"HELLO"换成字段名称,等等。

有人知道我为什么收到此错误吗?

zhangweiw 回答:预期为“ [”或AggregationStage,但找到“ {”。:MongoDB聚合不允许我在$ eq

$ match不接受raw aggregation expressions。而是使用$expr查询表达式在$ match中包含聚合表达式。

https://docs.mongodb.com/manual/reference/operator/aggregation/match/index.html#pipe._S_match

$expr: {
    $eq: [
      {
        $toLower: "HELLO"
      },"hello"
    ]
}

Aggregate command Find method

本文链接:https://www.f2er.com/2720320.html

大家都在问