【问题标题】:FieldPath field names may not start with '$'FieldPath 字段名称可能不以“$”开头
【发布时间】:2021-08-16 11:28:56
【问题描述】:

我正在使用以下代码

if (typeof(searchTerm) == "string") {
  let posts = await Post.reusablePostQuery([{
    $match: {
      $text: {
        $search: searchTerm}
      }
    }, {
      $sort: {
        score: {
          $meta: "textScore"
        }
      }
    }
  ])

我收到以下错误

FieldPath field names may not start with '$'

【问题讨论】:

  • 您正在尝试不带 aggregate 关键字的聚合方法语法。
  • Post 是什么?

标签: node.js mongodb


【解决方案1】:

我也遇到了同样的问题,但是当我删除 在它为我工作之前,下面的代码和逗号(,)

{
   $sort: {
        score: {
          $meta: "textScore"
        }
      }
  }

【讨论】:

    猜你喜欢
    • 2015-06-25
    • 1970-01-01
    • 2020-11-27
    • 2017-09-27
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    相关资源
    最近更新 更多