I'm building an expenses control app based on MERN Stack and I was wondering which way is the best to process data.
To be more specific, my expense data has the following model
{
"_id" : ObjectId("5eceb10f0b59a200a545c39b"),
"date" : ISODate("2019-10-10T00:00:00.000Z"),
"description" : "INTERT BILL",
"credit" : "",
"debit" : "-100",
"category" : "HOME",
"subcategory" : "INTERNET",
"__v" : 0
}
If I want to group expenses by category on a specific date, what would be the best way to do it?
Processing it on mongodb, through an aggregate query or fetch all expenses on a specific date range and grouping it on node.js before sending to client?
Desired output:
{
HOME: {
total: '-300',
subcategories: [
{
internet: { total: -100}
},
{
water: { total: -200 }
}
]
}
}