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