title: Add field of array element in MongoDB aggregation
body: <p>I have a collection of documents containing an array of objects:</p>
  
  <pre class="lang-js prettyprint-override"><code>db.collection.insert({
      arr: [
        { id: 1, text: 'foo' },
        { id: 2, text: 'bar' },
      ]
  });
  </code></pre>
  
  <p>Is there a way to extract/project/add a field of <strong>one</strong> element in that array? For example, the <code>text</code> field of the first element of the array. I've tried various variations of <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/" rel="noreferrer">$addFields</a> in <a href="https://mongoplayground.net/p/LEBQ1QjppEl" rel="noreferrer">MongoPlayground</a>,</p>
  
  <pre class="lang-js prettyprint-override"><code>db.collection.aggregate([
    {
        $addFields: { text1: '$arr.text' }
    }
  ]);
  </code></pre>
  
  <p>but nothing produced just one <code>text</code> field. At best, I got both, with the syntax above, but I want only one field, in order to use $type on it, because it appears <a href="https://github.com/mongodb/docs/pull/3586" rel="noreferrer"><code>$type</code> can't inspect array elements</a>.</p>