Project first item in an array to new field (MongoDB aggregation)
<p>I am using Mongoose aggregation (MongoDB version 3.2).</p>

<p>I have a field <code>users</code> which is an array. I want to <code>$project</code> first item in this array to a new field <code>user</code>.</p>

<p>I tried </p>

<pre><code>  { $project: {
    user: '$users[0]',
    otherField: 1
  }},

  { $project: {
    user: '$users.0',
    otherField: 1
  }},

  { $project: {
    user: ｛ $first: '$users'},
    otherField: 1
  }},
</code></pre>

<p>But neither works.</p>

<p>How can I do it correctly? Thanks</p>