FieldPath 字段名称不能以“$”开头

时间:2021-05-28 08:03:54

标签: node.js mongodb

我正在使用以下代码

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

我收到以下错误

<块引用>

FieldPath field names may not start with '$'

1 个答案:

答案 0 :(得分:0)

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

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