I have a collection balance with records
{
"_id" : "uezyuLx4jjfvcqMXN",
"amount" : "10",
"createdBy" : "AGuT6zQtSojvozbbg"
}
{
"_id" : "dCC8GrNdEjym3ryua",
"amount" : "10",
"createdBy" : "AGuT6zQtSojvozbbg"
}
I'm trying to calculate sum of amounts:
db.balance.aggregate([{$group:{_id:"$createdBy",total:{ $sum: "$amount"}}}])
Expected output:
{createdBy:AGuT6zQtSojvozbbg , total:20}
Actual output:
{ "_id" : "AGuT6zQtSojvozbbg", "total" : 0 }