Mongodb 按聚合顺序使用$$ROOT

Mongodb 按聚合顺序使用$$ROOT,mongodb,aggregation-framework,Mongodb,Aggregation Framework,我正在尝试以某种顺序从收集中获取数据: db.data.aggregate([ {$limit: 1000}, {$group: { _id: "$service", count: {$sum: 1}, data: {$push: '$$ROOT'} }} ]); 但是得到下一个错误: Error("Printing Stack Trace")@:0 ()@src/mongo/shell/utils.js:37 ([obj

我正在尝试以某种顺序从收集中获取数据:

db.data.aggregate([
    {$limit: 1000},
    {$group: {
        _id: "$service",
        count: {$sum: 1},
        data: {$push: '$$ROOT'}
    }}
]);
但是得到下一个错误:

Error("Printing Stack Trace")@:0
()@src/mongo/shell/utils.js:37
([object Array])@src/mongo/shell/collection.js:866
@(shell):6

uncaught exception: aggregate failed: {
    "errmsg" : "exception: FieldPath field names may not start with '$'.",
    "code" : 16410,
    "ok" : 0
}

我哪里出错了?

因此,根据评论,您需要一个MongoDB 2.6版来执行此操作。但当然,使用2.6对我来说很有用:

db.collection.aggregate([
{“$limit”:1000},
{“$group”:{
“_id”:空,
“计数”:{“$sum”:1},
“数据”:{“$push”:“$$ROOT”}
}}
])

您实际使用的是2.6版本吗?它刚刚发布,因此文档现在反映了最新版本。包名称已更改!我刚刚更新了10gen,得到了v2.4.10。塔克斯@user2381111感谢您声明我忘记了后端口。