使用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'}}])
待补充