当前位置: 代码迷 >> 综合 >> 【MongoDB】MongoDB数据库:Unrecognized pipeline stage name: '$count'
  详细解决方案

【MongoDB】MongoDB数据库:Unrecognized pipeline stage name: '$count'

热度:93   发布时间:2023-11-17 13:20:53.0

错误信息: 

ubuntu@ip-172-31-26-220:~/code$ mongod --version
db version v3.2.3
git version: b326ba837cf6f49d65c2f85e1b70f6f31ece7937
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
allocator: tcmalloc
modules: none
build environment:distmod: ubuntu1404distarch: x86_64target_arch: x86_64> db.scores.find()
{ "_id" : 1, "subject" : "History", "score" : 88 }
{ "_id" : 2, "subject" : "History", "score" : 92 }
{ "_id" : 3, "subject" : "History", "score" : 97 }
{ "_id" : 4, "subject" : "History", "score" : 71 }
{ "_id" : 5, "subject" : "History", "score" : 79 }
{ "_id" : 6, "subject" : "History", "score" : 83 }
> > db.scores.aggregate(
...   [
...     {
...       $match: {
...         score: {
...           $gt: 80
...         }
...       }
...     },
...     {
...       $count: "passing_scores"
...     }
...   ]
... )
assert: command failed: {"ok" : 0,"errmsg" : "Unrecognized pipeline stage name: '$count'","code" : 16436
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:23:13
doassert@src/mongo/shell/assert.js:13:14
assert.commandWorked@src/mongo/shell/assert.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1215:5
@(shell):1:12016-12-08T20:48:42.551+0800 E QUERY    [thread1] Error: command failed: {"ok" : 0,"errmsg" : "Unrecognized pipeline stage name: '$count'","code" : 16436
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
doassert@src/mongo/shell/assert.js:13:14
assert.commandWorked@src/mongo/shell/assert.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1215:5
@(shell):1:1> 

解决方案:$count阶段是在MongoDB 3.4中引入的。如果你想使用这个功能,请升级。

友情链接:mongodb官方社区

 

  相关解决方案