Выборка с группировкой
// Выборка с сортировкой
SELECT state, SUM(pop) AS totalPop FROM zipcodes
GROUP BY state HAVING totalPop >= 1000
db.zipcodes.aggregate( [
{ $group: { _id: "$state", totalPop: { $sum: "$pop" } } },
{ $match: { totalPop: { $gte: 1000 } } }
] )