预期的“[”或 AggregationStage 但找到“{”。:MongoDB 聚合不允许我在 $eq 中使用 $toLower

Expected "[" or AggregationStage but "{" found.: MongoDB aggregation doesn't let me use $toLower inside a $eq

我写了一个 MongoDB 管道,里面有这段代码:

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

这是在 Mongo Compass

中的截图

我希望它只是 return 正确,并且“$match”一切(现在)。 最终我会将 "HELLO" 替换为字段名称等

有谁知道我为什么会收到这个错误?

$match does not accept raw aggregation expressions. Instead, use a $expr query expression to include aggregation expression in $match.

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

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

Aggregate command Find method