title: Add sequence number to items from mongodb query
body: <p>I have MongoDB collection <code>items</code> with following documents:</p>
  <pre><code>{ &quot;name&quot;: &quot;First&quot;, &quot;value&quot;: 8 },
  { &quot;name&quot;: &quot;Second&quot;, &quot;value&quot;: 2 },
  { &quot;name&quot;: &quot;Third&quot;, &quot;value&quot;: 5 }
  </code></pre>
  <p>I would like to sort them by <code>name</code> or <code>value</code> and then add sequence number (<code>index</code> property) to each of them (first item will have <code>&quot;index&quot;: 1</code>, second <code>&quot;index&quot;: 2</code>, etc.). So for this query:</p>
  <pre><code>db.items.aggregate([{ $sort: { &quot;value&quot;: 1 } }])
  </code></pre>
  <p>result should be:</p>
  <pre><code>{ &quot;name&quot;: &quot;Second&quot;, &quot;value&quot;: 2, &quot;index&quot;: 1 },
  { &quot;name&quot;: &quot;Third&quot;, &quot;value&quot;: 5, &quot;index&quot;: 2 },
  { &quot;name&quot;: &quot;First&quot;, &quot;value&quot;: 8, &quot;index&quot;: 3 }
  </code></pre>
  <p>This should also works with <code>$skip</code>. With <code>{ &quot;$skip&quot;: 1 }</code>, result should be items with indexes <code>2, 3</code>, not <code>1, 2</code>. Is there any way to do this using pure MongoDB, without any application logic?</p>