以汇总顺序使用$$ ROOT [英] Using $$ROOT in aggregation order
本文介绍了以汇总顺序使用$$ ROOT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试以某种顺序从集合中获取数据:
I'm try get data from collection with some order:
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对我来说是有效的:
So per the comment you need a MongoDB version 2.6 do do this. But of course using 2.6 this works for me:
db.collection.aggregate([
{ "$limit": 1000 },
{ "$group": {
"_id": null,
"count": { "$sum": 1},
"data": { "$push": "$$ROOT" }
}}
])
这篇关于以汇总顺序使用$$ ROOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文