mongoDB数据库:Unrecognized pipeline stage name: '$count'

版权声明:此博客为个人博客,不涉及商业用途,仅提供学习参考,内容均来自个人原创以及互联网转载和摘录。 --------------------- 本文来自 路西法Lucifer 的CSDN 博客 ,全文地址请点击: https://blog.csdn.net/qq_37495786/article/details/80346181
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: ubuntu1404
    distarch: x86_64
    target_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:1
 
2016-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官方社区

 

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页