mongodb 分组统计: 按deviceId、tenant分组,统计总记录条数、求和workload
db.RollerWorkingPeriod.aggregate( {
$match:{tenant:"A01"}},
{$group:{ _id: {deviceId:"$deviceId",tenant:"$tenant"},
count:{$sum:1},
seconds:{$sum: "$seconds"}}
} )
删除senconds列
db.RollerWorkingPeriod.update(
{},
{ $unset: { seconds: 1} },
false,
true
)
添加senconds列
db.RollerWorkingPeriod.update(
{},
{ $set: { seconds: 2} },
false,
true
)