Is there a way to get the amount of money paid per Sport's category? It can't be restricted only to "John," but in all collection documents.
Expected query return for data provided:
{
{"Fight": [100,95] },
{"Running": [50] }
}
Example of data:
{"_id":"5z621578b0ce483b9866fb1f",
"Name":"John",
"Sports":[
{"Category":"Fight",
"Billing":[
{"Month":"Jan",
"Status":"Paid",
"Price":100},
{"Month":"Feb",
"Status":"Not Paid",
"Price":125},
{"Month":"Mar",
"Status":"Paid",
"Price":95}
]
},
{"Category":"Running",
"Billing":[
{"Month":"Jan",
"Status":"Not Paid",
"Price":200},
{"Month":"Feb",
"Status":"Paid",
"Price":50}
]
}
]
}
In other words: I need to compare the billing Status inside every nested object and check if it's"Paid", then if true, add the respective billing object Price to the respective Sport's Category array.
For all documents in the collection, with multiple sport's categories and multiple billing's month. But always same nested structure.
Thank you in advance!