陪伴而非守候
mongodb提供了聚合函数完成类似的sum函数的功能比如:$sum案例:/*** select sum(pop) total from zipsController group by state*/exports.sumGroupByStateDemoAsync = function (opts) {var results = {error_code: -1, error_msg: "error"};var pipeline =[{$group: {_id: "$state",totalpop: {$sum: "$pop"}}}];return opts.dbs.csdb.collection("zipsController").aggregateAsync(pipeline).timeout(opts.configs.timeoutnormal).then(function (value) {if (value) {results.error_code = 0;results.error_msg = "ok";results.accdetail = value;} else {//可选results.error_code = 20001;results.error_msg = "数据不存在";results.accdetail = value;}return results;});}