mongodb - Using $$ROOT in aggregation order -
i'm try data collection order:
db.data.aggregate([ {$limit: 1000}, {$group: { _id: "$service", count: {$sum: 1}, data: {$push: '$$root'} }} ]);
but next error:
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 '$'.", "code" : 16410, "ok" : 0 }
where did go wrong?
so per comment need mongodb version 2.6 do this. of course using 2.6 works me:
db.collection.aggregate([ { "$limit": 1000 }, { "$group": { "_id": null, "count": { "$sum": 1}, "data": { "$push": "$$root" } }} ])
Comments
Post a Comment