Lets say I have document like below
{
"_id" : 1,
"Quality" : [
"HIGH",
"LOW",
"LOW",
"HIGH"
],
"Pages" : [
10,
10,
12,
17
]
}
I need result as
{
"_id" : 1,
"HIGH" : 27
"LOW" : 22
}
I need to create two attributes HIGH and LOW as per the Quality by summing their corresponding index position values of Pages array.
I though of using $filter and $arrayElemAt, but i could not get index position while filtering on Pages attribute
high : { $sum:{ $filter: { input: "$Pages", as: "noOfPages", cond: {"$eq":[{ $arrayElemAt: ["$Quality", **Need to pass index position of $pages while filtering**]}, "HIGH"]}}}}
Thanks In Advance.