mongodb数据如下:
db.cpc_0103.find()
{ "a" : 8, "b" : "108177_200701010000", "c" : 108177, "d" : 180, "e" : 1404917, "f" : "U盘", "g" : 184543, "h" : "U盘网上批发市场", "i" : 90, "j" : 3, "k" : 3, "l" : "", "m" : "2007-01-01 00:00:00", "n" : "", "o" : "", "p" : -1, "q" : "--", "r" : 0, "s" : "" }
......
......
如何对其中的一列数据SUM,
xreport-cpc:PRIMARY> var reduce = function(key, values){
... ... var count=0;
... ... values.forEach(function(v) {
... ... count+=v.p;
... ... });
... ... return {count: count};
... ... };
xreport-cpc:PRIMARY> var reduce = function(key, values){
... var count=0;
... values.forEach(function(v) {
... count+=v.cm;
... });
... return {count: count};
... };
xreport-cpc:PRIMARY> var s = db.c.find();
xreport-cpc:PRIMARY> var s = db.test.find();
xreport-cpc:PRIMARY> reduce("total_cm", s);
执行结果如下:
{ "count" : 20328860 }