Database

[{"account_id":1,"pub":{"cpm":NumberDecimal("1"),"monthly":NumberDecimal("1.5")},"time":ISODate("2022-01-01"),},{"account_id":2,"pub":{"cpm":NumberDecimal("3"),"monthly":NumberDecimal("3.5")},"time":ISODate("2022-01-01"),},{"account_id":1,"pub":{"cpm":NumberDecimal("2"),"monthly":NumberDecimal("2.5")},"time":ISODate("2022-01-01"),},{"account_id":2,"pub":{"cpm":NumberDecimal("4"),"monthly":NumberDecimal("4.5")},"time":ISODate("2022-01-01"),}]

Query

db.collection.aggregate([{"$group":{"_id":"$account_id","pub__cpm":{$sum:"$pub.cpm"},"pub__monthly":{$sum:"$pub.monthly"}}},{"$project":{"pub":{"cpm":"$pub__cpm","monthly":"$pub__monthly"}}}])

Result