Database

db={"transactions":[{"_id":"tx1","customerName":"Alice","date":ISODate("2024-01-01"),"amount":100},{"_id":"tx2","customerName":"Alice","date":ISODate("2024-01-02"),"amount":200},{"_id":"tx3","customerName":"Alice","date":ISODate("2024-02-01"),"amount":300},{"_id":"tx4","customerName":"Alice","date":ISODate("2024-03-01"),"amount":400}]}

Query

db.transactions.aggregate([{"$group":{"_id":{$dateTrunc:{date:"$date",unit:"month"}},"totalAmount":{"$sum":"$amount"}}}])

Result