当前位置:Gxlcms > 数据库问题 > mongodb 聚合操作

mongodb 聚合操作

时间:2021-07-01 10:21:17 帮助过:24人阅读

$whoisserver_id,total:{$sum:1}}})

查询出来的结果如下:

技术分享

  • 如果查询总的数量:
db.anhui.aggregate({$group:{_id:null,total:{$sum:1}}})

 

技术分享

  • 以下查询先根据条件过滤然后统计  
db.anhui.aggregate({$match:{mx:{$exists:1}}},{$group:{_id:‘$whoisserver_id‘,total:{$sum:1}}})
  • 首先过滤数据相当于 sql 语句中where 操作,然后分组 count  ,然后 匹配数量大于30的 信息
db.anhui.aggregate({$match:{mx:{$exists:1}}},{$group:{_id:‘$whoisserver_id‘,total:{$sum:1}}},{$match:{total:{$gte:30}}})

 

以下为查询到的数据

技术分享

查询 

db.anhui.aggregate({$match:{mx:{$exists:1}}},{$group:{_id:‘$mx.brand_id‘,total:{$sum:1}}})

 

mongodb 聚合操作

标签:技术分享   sql   ota   分析   style   .com   where   com   条件   

人气教程排行