How can I translate the following Sql query for Mongo?:
select a,b,sum(c) csum from coll wh
Using the aggregate framework, you can do the following:
db.coll.aggregate({
$group: {
_id: "$a",
countA: { $sum: 1},
sumC:{ $sum: "$c"},
},
$sort:{a:1}
});
However, if you have too much data you may get the following error message:
{
"errmsg" : "exception: aggregation result exceeds maximum document size (16MB)",
"code" : 16389,
"ok" : 0
}
See more about SQL to Mongo translation here: http://docs.mongodb.org/manual/reference/sql-aggregation-comparison/