1
turing Apr 30, 2014
搜索一下 $inc 操作符
|
2
liangdi Apr 30, 2014 via Android
有$sum
|
4
hydrazt Apr 30, 2014
mapreduce
|
6
hydrazt Apr 30, 2014
|
7
turing Apr 30, 2014
累加求和用 mapReduce
model.mapReduce({ map: function() { emit(this.earn, 1) }, reduce: function(key, values){ return Array.sum(values); }, query: { ... // 查询参数 } }); http://docs.mongodb.org/manual/core/map-reduce/ |
9
wbean Apr 30, 2014 mongo中简单的统计需求不用祭出mapreduce这种大杀器。
Aggregation就可以了。 通过一些基础管道操作,如$project,$match,$group,$limit,$skip,$sort 和 一些 常用表达式如$sum,$avg,$min,$max 等实现基础的统计需求 db.collection.aggregate( [ $match:{} $group:{$_id:"",total:{$sum:"$amount"}} ] ); |
10
benleewindy May 1, 2014
@turing Reduce本身就是对collection做迭代归并操作,肯定能满足,简单需求似乎过重。。。。
|