I have a following document structure
Users:[{
"name": "test",
"leaveBalance": 20,
"leaveHistory": [
{
type: "Leave",
numberofDays:2,
status:"Approved"
},
{
type: "WFH",
numberOfDays:1,
status: "Approved"
},
{
type: "Leave",
numberOfDays:2,
status: "Cancelled"
}
]
},
{
...
}
]
I need a query to find the total number of days a person took leave from this collection. number of days of leave is considered only if status is Approved and leave type is "Leave". Is there a way in mongodb to query and find the number ?