I have collection named transactions in Mongodb which stores the expenses or income along with bank details and date. I want to show the total expenses for current month. For example, if I am storing 3 transactions having 3 expenses each of $10 $20 for month of December and $20 for the month of November, I should get the output as $30. I have stored the date as the ISO date object. How should I compare the months in the database with the current month in the aggregate function of mongodb. Following is the code I am trying to get the total expenses for the current month :
result = await transactionCollection.aggregate([{
$group : {
_id : {trans_type : "$transaction_type"},
amount : {$sum : "$amount"}
}
},
{
$match : {date.getMonth() : new Date().getMonth()}
}]).toArray()
Any tips or suggestions are deeply appreciated.