您当前的位置: 首页 >  mongodb

MongoDB aggregate聚合分组查询

彭世瑜 发布时间:2020-11-02 22:10:14 ,浏览量:2

聚合查询语句

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

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 2浏览

    0关注

    2771博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0445s