1、多个字段分组 $group

db.collection.aggregate([{$group:{"_id":{"creator":"$creator", "code":"$code"}, total: {$sum: 1}}}]);

2、group后,增加其它段返回

例如, $max 返回最大一条,$first 返回第一条 等等

db.collection.aggregate([{$group:{"_id":"$creator", "createTime":{$max:"$createTime"}, total: {$sum: 1}}}]);

2、去重统计总数

db.collection.aggregate([{$group:{"_id":"$loginUser"}},{$group: {"_id":1, "total":{$sum: 1}}}]);