node.js - 我想通过聚合对mongo中的count字段求和,数组是动态的,格式是spend_imp->today_date(everyday new array gen,)->count.......)
问题描述
array = "spend_imp" : {
"2019-11-19" : {
"created" : 1574167415264.0,
"count" : 1
},
"2019-11-20" : {
"count" : 4,
"created" : 1574229189457.0
}
}
try {
Main_add_list.aggregate( [
{ $match: {"add_id" : data.add_id } },
{$project:{
"_id":1,
"spend_imp":1,
"Total_spend":{$sum:"$spend_imp.2019-11-19"},
}},
] ).then((result) => {
return callback(result);
}).catch((err) =>{
console.log(err);
return callback(err);
})
}
catch(e){ return callback(null); }
我动态地制作数组。
数组格式为-> today_date( gen.spend_imp
下每天新的嵌套数组) -> today_date 中的字段(例如,2019 年 11 月 20 日)。所以我想总结一下。例如,我有 2 个数组和,所以我想要两个数组的总和。spend_imp
count
count
11/19/2019
11/20/2019
解决方案
推荐阅读
- shiny - Flexdashboard with Shiny - 小部件字体样式
- php - Callback_query 不起作用(Telegram php 机器人)
- forms - 如何自定义 TextFormField 标签动画?
- php - 检查包含的 php 中的 url 参数?
- r - 为多图面板添加注释后修改空间
- c++ - C/C++ 从 wint_t 打印英镑符号
- c++ - 在可变参数模板上混合 const 和非 const 变量
- python - How to tell pandas to read columns from the left?
- javascript - 通过 JS 覆盖过渡的 CSS 属性会使过渡停止工作
- python - 2个相似数据帧之间的数学运算