title: Mongodb aggregate addField that contains the current object position in the array query
body: <p>After the last aggregate pipeline I receive the current array:</p>
  <pre><code>[{
      &quot;cdrId&quot;: &quot;61574b3e58fb1cae1494df2c&quot;,
      &quot;date&quot;: &quot;2021-10-01T17:54:06.057Z&quot;,
      &quot;intentType&quot;: &quot;FALLBACK&quot;
  },
  {
      &quot;cdrId&quot;: &quot;61574b3e58fb1cae1494df2c&quot;,
      &quot;date&quot;: &quot;2021-10-01T17:54:06.057Z&quot;,
      &quot;intentType&quot;: &quot;FAQ&quot;
  },
  {
      &quot;cdrId&quot;: &quot;61570b37522aba5e2f205356&quot;,
      &quot;date&quot;: &quot;2021-10-01T13:20:55.601Z&quot;,
      &quot;intentType&quot;: &quot;TRANS/DISAM&quot;
  },
  {
      &quot;cdrId&quot;: &quot;61570b37522aba5e2f205356&quot;,
      &quot;date&quot;: &quot;2021-10-01T13:20:55.601Z&quot;,
      &quot;intentType&quot;: &quot;FAQ&quot;
  }]
  </code></pre>
  <p>I'm looking to add a index field showing the current position of the object in the array. The output is going to be something like this:</p>
  <pre><code>[{
      &quot;index&quot;: 0,
      &quot;cdrId&quot;: &quot;61574b3e58fb1cae1494df2c&quot;,
      &quot;date&quot;: &quot;2021-10-01T17:54:06.057Z&quot;,
      &quot;intentType&quot;: &quot;FALLBACK&quot;
  },
  {
      &quot;index&quot;: 1,
      &quot;cdrId&quot;: &quot;61574b3e58fb1cae1494df2c&quot;,
      &quot;date&quot;: &quot;2021-10-01T17:54:06.057Z&quot;,
      &quot;intentType&quot;: &quot;FAQ&quot;
  },
  {
      &quot;index&quot;: 2,
      &quot;cdrId&quot;: &quot;61570b37522aba5e2f205356&quot;,
      &quot;date&quot;: &quot;2021-10-01T13:20:55.601Z&quot;,
      &quot;intentType&quot;: &quot;TRANS/DISAM&quot;
  },
  {
      &quot;index&quot;: 3,
      &quot;cdrId&quot;: &quot;61570b37522aba5e2f205356&quot;,
      &quot;date&quot;: &quot;2021-10-01T13:20:55.601Z&quot;,
      &quot;intentType&quot;: &quot;FAQ&quot;
  }]
  </code></pre>
  <p>I will use this value if the next pipe sort this array. So I have it's original position before this sorting.</p>
  <p>Is there a way that I can do this with aggregate? I'm using MongoDB 4.2.</p>