Where to process data on MERN stack?
You should let MongoDB to the grouping, especially if you're dealing with a big dataset. The reason for that is that you could potentially block the event-loop by long running operations. Here's an aggregation query that should help you get started:
yourModel.aggregate([ { $match: { date: yourDateToMatch } }, { // you need this conversion stage in order to be able to do maths with your debit field $addFields: { convertedDebit: { $toDecimal: "$debit" } } }, { $group: { _id: "$category", total: { $sum: "$convertedDebit" }, // add grouping options for subcategories } } ])
and just return the result using node.