title: Match with OR clause after Unwind in MongoDB aggregate query
body: <p>I have a MongoDB aggregate query like this</p>
  <pre><code>[{ &quot;$match&quot; : { &quot;isDeleted&quot; : false } }
  , { &quot;$match&quot; : { &quot;$or&quot; : [{ &quot;arrayCol.col_1&quot; : &quot;Yes&quot;, &quot;arrayCol.subArrCol.col_2&quot; : 10 }, { &quot;arrayCol.subArrCol.col_3&quot; : 2000 }] } }
  , { &quot;$project&quot; : { &quot;_id&quot; : 0, &quot;col_0&quot; : &quot;$col_0&quot;, &quot;col_1&quot; : &quot;$arrayCol.col_1&quot;, &quot;col_2&quot; : &quot;$arrayCol.subArrCol.col_2&quot;, &quot;col_3&quot; : &quot;$arrayCol.subArrCol.col_3&quot; } }]
  </code></pre>
  <p>which is currently returning 2 documents like below</p>
  <pre><code>/* 1 */
  {
      &quot;col_0&quot; : &quot;xyz&quot;,
      &quot;col_1&quot; : &quot;Yes&quot;,
      &quot;col_2&quot; : [
          10
      ],
      &quot;col_3&quot; : [
          2013,
          1995
      ]
  },
  
  /* 2 */
  {
      &quot;col_0&quot; : &quot;pqr&quot;,
      &quot;col_1&quot; : &quot;Yes&quot;,
      &quot;col_2&quot; : [
          9,
          10
      ],
      &quot;col_3&quot; : [
          2000,
          2000
      ]
  }
  </code></pre>
  <p>Now I want to unwind both &quot;col_2&quot; and &quot;col_3&quot;, but it should return only those docs like before, ie those docs with either col_2 = 10 or col_3 = 2000.</p>
  <p>My expected result set is like follows,</p>
  <pre><code>/* 1 */
  {
      &quot;col_0&quot; : &quot;xyz&quot;,
      &quot;col_1&quot; : &quot;Yes&quot;,
      &quot;col_2&quot; : 10,
      &quot;col_3&quot; : 2013
  },
  
  /* 2 */
  {
      &quot;col_0&quot; : &quot;pqr&quot;,
      &quot;col_1&quot; : &quot;Yes&quot;,
      &quot;col_2&quot; : 9,
      &quot;col_3&quot; : 2000
  }
  /* 3 */
  {
      &quot;col_0&quot; : &quot;pqr&quot;,
      &quot;col_1&quot; : &quot;Yes&quot;,
      &quot;col_2&quot; : 10,
      &quot;col_3&quot; : 2000
  }
  </code></pre>
  <p>If the match condition was an AND clause, then I could have added the same match condition once again after the unwinds to eliminate the wrong values.
  But how can I solve this in OR clause/ Can anyone please help?
  I am new to MongoDB.</p>
  <p>Documents in my collection are as follows,</p>
  <pre><code>{
      &quot;_id&quot;: &quot;1234-5f33-4703-be7f-3ea679951af3&quot;,
      &quot;col_0&quot;: &quot;xyz&quot;,
      &quot;arrayCol&quot;: {
          &quot;col_1&quot;: &quot;Yes&quot;,
          &quot;subArrCol&quot;: [
              {
                  &quot;col_2&quot;: 10,
                  &quot;col_3&quot;: 2013
              },
              {
                  &quot;col_3&quot;: 1995
              }
          ]
      }
  },
  {
      &quot;_id&quot;: &quot;5678-5f33-4703-be7f-3ea679951af3&quot;,
      &quot;col_0&quot;: &quot;pqr&quot;,
      &quot;arrayCol&quot;: {
          &quot;col_1&quot;: &quot;Yes&quot;,
          &quot;subArrCol&quot;: [
              {
                  &quot;col_2&quot;: 9,
                  &quot;col_3&quot;: 2000
              },
              {
                  &quot;col_2&quot;: 10,
                  &quot;col_3&quot;: 2000,
                  &quot;col_4&quot;: &quot;abc&quot;
              }
          ]
      }
  }
  </code></pre>