首页 > 解决方案 > 无法识别的管道阶段名称:'$planCacheStats'

问题描述

当我在 MongoDB 版本 4.0.12 上运行以下聚合命令时出现以下错误。从我读到的关于该错误的信息来看,它看起来像是一个语法问题。但这是有人给我的,他们说它有效。有人可以告诉我我做错了什么吗?

db.bookings.aggregate( [ { $planCacheStats: { } } ] )

db.bookings.aggregate( [ { $planCacheStats: { } } , { $project: {createdFromQuery: 1, queryHash: 1 } } ] )

输出:

E QUERY    [js] Error: command failed: {
    "ok" : 0,
    "errmsg" : "Unrecognized pipeline stage name: '$planCacheStats'",
    "code" : 40324,
    "codeName" : "Location40324"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:536:17
assert.commandWorked@src/mongo/shell/assert.js:620:16
DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1062:12
@(shell):1:1

标签: databasemongodbnosqlaggregate

解决方案


由于您使用的是 4.0 版,因此不支持它。所以你得到unrecognised pipeline error

$planCacheStats- 4.2 版中的新功能

因此从 4.2 开始支持它。

参考


推荐阅读