title: How do I $concat fields in an array of objects?
body: <h1>What I have</h1>
  
  <p>I have the following documents coming into my aggregation pipeline:</p>
  
  <pre><code>[
      { 
          "email" : "email@example.com", 
          "name"  : "Organization Name",  
          "users" : [
              {
                  "lastName"  : "Nye", 
                  "firstName" : "Bill", 
                  "email"     : "bnye@example.com"
              },
              {
                  "lastName"  : "Rogers", 
                  "firstName" : "Mr.", 
                  "email"     : "mrrogers@example.com"
              }
          ]
      },
      ...
  ]
  </code></pre>
  
  <h1>What I want</h1>
  
  <p>Using<code>$project</code> I want to <code>$concat</code> the <code>firstName</code> and <code>lastName</code> fields within each of the array subdocuments to get the following result:</p>
  
  <pre><code>{ 
      "email" : "email@example.com", 
      "name"  : "Organization Name",  
      "users" : [
          {
              "name"  : "Bill Nye", 
              "email" : "bnye@example.com"
          },
          {
              "name"  : "Mr. Rogers", 
              "email" : "mrrogers@example.com"
          }
      ]
  }
  </code></pre>
  
  <h1>What I've tried - Attempt #1</h1>
  
  <p>I've tried the following aggregation:</p>
  
  <pre><code>db.organizations.aggregate([
      {
          $project: {
              email : 1,
              name  : 1,
              users : {
                name  : { $concat : [ "$users.firstName", " ", "$users.lastName" ] },
                email : 1
              }
          }
      }
  ]);
  </code></pre>
  
  <p>... but I get the following error:</p>
  
  <blockquote>
    <p>$concat only supports strings, not Array</p>
  </blockquote>
  
  <h1>What I've tried - Attempt #2</h1>
  
  <p>I've also tried the following aggregation:</p>
  
  <pre><code>db.organizations.aggregate([
      {
          $project: {
              email : 1,
              name  : 1,
              users : {
                name  : { $concat : [ "$firstName", " ", "$lastName" ] },
                email : 1
              }
          }
      }
  ]);
  </code></pre>
  
  <p>... but <code>name</code> always returns <code>null</code>.</p>
  
  <p>I feel as if this should be a relatively simple thing to do, however, I'm completely stumped.</p>
  
  <p><strong>How do I get the results that I'm looking for?</strong></p>