3
我有一個集合平衡與記錄MongoDB的總和查詢返回零
{
"_id" : "uezyuLx4jjfvcqMXN",
"amount" : "10",
"createdBy" : "AGuT6zQtSojvozbbg"
}
{
"_id" : "dCC8GrNdEjym3ryua",
"amount" : "10",
"createdBy" : "AGuT6zQtSojvozbbg"
}
我試圖計算金額的總和:
db.balance.aggregate([{$group:{_id:"$createdBy",total:{ $sum: "$amount"}}}])
預期輸出:
{createdBy:AGuT6zQtSojvozbbg , total:20}
實際產量:
{ "_id" : "AGuT6zQtSojvozbbg", "total" : 0 }