title: MongoDB Multiple Aggreations in nested Array
body: <p>I'm trying to merge two aggregation statements related to a nested Array and can't figure it out.</p>
  <p>I have following MongoDB structure and want to extract some Data.</p>
  <pre><code>{
    &quot;MS_Identification&quot;: &quot;Sim7500Triple&quot;,
    &quot;LastTimeUpdated&quot;: {
      &quot;$date&quot;: &quot;2022-08-02T10:08:25.671Z&quot;
    },
    &quot;Start&quot;: {
      &quot;$date&quot;: &quot;2022-07-25T11:44:48.769Z&quot;
    },
    &quot;End&quot;: {
      &quot;$date&quot;: &quot;2022-07-25T12:56:10.651Z&quot;
    },
    &quot;Batches&quot;: [
      {
        &quot;BatchID&quot;: &quot;e4f83ed1-87f6-46c3-a651-e906b904af55&quot;,
        &quot;Start&quot;: {
          &quot;$date&quot;: &quot;2022-06-03T12:32:40.094Z&quot;
        },
        &quot;End&quot;: {
          &quot;$date&quot;: &quot;2022-06-03T12:34:53.574Z&quot;
        },
        &quot;Queue&quot;: [
          {
            &quot;SampleGuid&quot;: &quot;7155c10b-e7ec-4799-90c2-80f2ca38bcde&quot;,
            &quot;SampleName&quot;: &quot;AFT(AST(C08))&quot;,
            &quot;DataAcquisitionEstimatedDuration&quot;: 61,
            &quot;DataAcquisitionEstimatedStartTime&quot;: {
              &quot;$date&quot;: &quot;2022-06-03T12:32:40.094Z&quot;
            },
            &quot;AutoProcessState&quot;: &quot;Waiting&quot;,
            &quot;DataAcquisitionState&quot;: &quot;Passed&quot;,
            &quot;FileTransferState&quot;: &quot;None&quot;
          }
        ]
      }
    ]
  }
  </code></pre>
  <p>At first,  I excluded some unnecessary fields and added a Datediff of Batches.Start and Batches.End</p>
  <pre><code>db.inventory.find({},{
    _id:0,
    MS_Identification:1,
    LastTimeUpdated:1,
    Batches:{Durration_s: {
          $dateDiff:
            {
            startDate: &quot;$Start&quot;,
            endDate: &quot;$End&quot;,
            unit: &quot;second&quot;
            }
          },
          BatchID:1,
          Queue:1
    }
  })
  </code></pre>
  <p>In a Next step i wanted to combine the previus statement with</p>
  <pre><code>Batches:{$slice: -100}
  </code></pre>
  <p>Somehow I can't figure out the Syntax for that.
  I only managed to override my &quot;Batches&quot;-statement, and I can't combine Both ($DateDiff:{...} and $Slice: -100).</p>
  <p>Thanks for any Help/ Hint on how to solve this!</p>