MongoDB使用聚合$facet报错

查询条件如下

db.doc_user_orders.aggregate([
  {
        $match: {
            "orgGroup": "汽车事业群"
        }
    },
    {
        $facet: {
            "data": [
                
                {
                    $sort: {
                        "_id": -1
                    }
                },
                {
                    $skip: 0
                },
                {
                    $limit: 10
                }
            ],
            "total": [
                
                {
                    $count: "total"
                }
            ]
        }
    }
])

报错如下:

assert: command failed: {
    "ok" : 0,
    "errmsg" : "Unrecognized pipeline stage name: '$facet'",
    "code" : 16436
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:13:14
assert.commandWorked@src/mongo/shell/assert.js:287:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1312:5
@(shell):1:1

2021-04-16T15:35:51.449+0800 E QUERY    [thread1] Error: command failed: {
    "ok" : 0,
    "errmsg" : "Unrecognized pipeline stage name: '$facet'",
    "code" : 16436
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:13:14
assert.commandWorked@src/mongo/shell/assert.js:287:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1312:5
@(shell):1:1

这个是什么原因?

阅读 2.6k
1 个回答

写的没问题啊, facet是3.4以上的, 版本不对?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题