title: Iterate over double nested array in mongodb
body: <p>I have the following document:</p>
  
  <pre><code>{
    "_ID": "234",
    "sub": {
      "abcId": "123",
      "subElems": [
        {
          "abcId": "345",
          "subElems": [
            {
              "abcId": "676",
              "subElems": [
                {
                  "abcId": "567"
                },
                {
                  "abcId": "567b",
                  "crit1": false,
                  "crit2": "someId",
                  "crit3": "2013-07-30T22:00:00.000+0000",
                  "crit4": "ABC"
                },
                {
                  "abcId": "567c",
                  "crit1": true,
                  "crit3": "2013-07-30T22:00:00.000+0000",
                  "crit4": "ABC"
                },
                {
                  "abcId": "567d",
                  "crit1": true,
                  "crit3": "2018-11-30T22:00:00.000+0000",
                  "crit4": "ABC"
                }
              ]
            },
                      {
              "abcId": "678",
              "subElems": [
                {
                  "abcId": "568"
                },
                {
                  "abcId": "568b",
                  "crit1": false,
                  "crit2": "someId",
                  "crit3": "2013-07-30T22:00:00.000+0000",
                  "crit4": "ABC"
                },
                {
                  "abcId": "568c",
                  "crit1": true,
                  "crit3": "2013-07-30T22:00:00.000+0000",
                  "crit4": "ABC"
                },
                {
                  "abcId": "568d",
                  "crit1": true,
                  "crit3": "2018-11-30T22:00:00.000+0000",
                  "crit4": "ABC"
                }
              ]
            }
          ]
        }
      ]
    }
  }
  </code></pre>
  
  <p>I need to iterate over all <code>sub.subElems.0.subElems</code> (in this case the nested documents with <code>abcId</code> 676 and 678)</p>
  
  <p>Each of those 2 again have an array of objects called <code>subElems</code>.</p>
  
  <p>I need to find all ojects in this <code>subElems</code> array that match the following criteria (AND, not OR):</p>
  
  <pre><code>crit1 = true
  crit4 = ABC
  crit2 = null
  crit3 = more than a year ago
  </code></pre>
  
  <p>Given the collectin above, I need:</p>
  
  <p><code>567c</code> and <code>568c</code></p>
  
  <p>I have a tried various aggregations.</p>
  
  <p>I thought I could do something like <code>unwind sub.subElems.0.subElems</code> and then access its <code>subElems</code> array and iterate over that.</p>
  
  <p>What I don't know how to do is select a nested aray of objects (whose path I know) but then iterate over the elements in this array and again iterate over an array in those objects.</p>
  
  <p>Thanks for help and tips!</p>