首页 > 解决方案 > Node JS with MongoDB Aggregate with $unwind not working $addFields, $sort, $match 在聚合管道中

问题描述

我是 Node Js 的新手。我正在尝试使用 unwind 关键字解决聚合问题。但是当我尝试添加新字段或排序或匹配时,它会返回这样的错误

error": {
        "ok": 0,
        "errmsg": "Unrecognized pipeline stage name: '$addFields'",
        "code": 16436,
        "name": "MongoError",
        "statusCode": 500,
        "status": "error"

我编写如下代码(仅部分)

      $addFields: {
        month: '$_id'
      }
    },
    {
      $sort: {
        month: 1
      }
    },
    {
      $project: {
        _id: 0
      }
    }```

标签: node.jsmongodbexpressaggregatepipeline

解决方案


推荐阅读