聚合查询语句
db.collection.aggregate([{$group : {_id : "$source", total : {$sum : 1}}}])
{
"result" : [
{
"_id" : "36kr",
"total" : 2
},
{
"_id" : "sina",
"total" : 1
}
],
"ok" : 1
}
语句类似
select source, count(*) from collection group by source
常用操作
$limit:用来限制MongoDB聚合管道返回的文档数。
$skip:在聚合管道中跳过指定数量的文档,并返回余下的文档。
$sort:将输入文档排序后输出。
参考 https://www.runoob.com/mongodb/mongodb-aggregate.html