亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

mongodb有能夠sum的命令嗎?

mongodb有能夠sum的命令嗎?

烙印99 2018-11-20 22:18:44
mongodb有能夠sum的命令嗎
查看完整描述

1 回答

?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

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;
});
}

查看完整回答
反對 回復 2018-12-10
  • 1 回答
  • 0 關注
  • 802 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號