标签:gre 示例 mysql group by mongo star agg 筛选条件 select
使用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‘}}])
待补充
标签:gre 示例 mysql group by mongo star agg 筛选条件 select
原文地址:https://www.cnblogs.com/Jaryer/p/14647606.html