有没有办法获得每个运动类别支付的金额?它不能仅限于“John”,而是在所有集合文档中。
所提供数据的预期查询返回:
{
{"Fight": [100,95] },
{"Running": [50] }
}
数据示例:
{"_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}
]
}
]
}
换句话说:我需要比较每个嵌套对象中的计费状态并检查它是否为“已支付”,如果为真,则将 相应的计费对象价格添加到相应的运动类别数组中。
对于集合中的所有文档,具有多个运动类别和多个计费月份。但总是相同的嵌套结构。
先感谢您!