时间:2021-07-01 10:21:17 帮助过:22人阅读
使用mongo db 的 aggregate 进行聚合操作,改操作传入的参数是一个数组
示例:
{$match : {
‘os‘: ‘win‘
}
}
示例:
{$group : {
_id:"$name",
count :{
$sum:1
}
}
}
# mysql
select name,count(*) from table group by name;
# mongo shell
db.collection.aggregate([{$group:{_id:‘name‘,count:{$sum:1}}}])
# mysql
select name,count(*) from table where os=‘win‘; group by name;
# mongo shell
db.collection.aggregate([{$match:{os:‘win‘}},{$group:{_id:‘name‘,count:{$sum:1}}}])
# mysql
select name,count(*) from table group by name where os=‘win‘ ;
# mongo shell
db.collection.aggregate([{$group:{_id:‘name‘,count:{$sum:1}}},{$match:{os:‘win‘}}])
待补充
mongodb 聚合查询
标签:gre 示例 mysql group by mongo star agg 筛选条件 select