title: How to search for users by both first and last name with MongoDB?
body: <p>I have a basic collection of users that have their <code>firstName</code>, <code>lastName</code> and a few other details.</p>
  
  <p>How would I simply search for users by a combination of both names, or partial search?</p>
  
  <p>For example, for a collection of:</p>
  
  <pre><code>{
     firstName: Bob,
     lastName: Jerry
  }, {
     firstName: Clark,
     lastName: Mcbobby
  }
  </code></pre>
  
  <p>If the search term was <code>bob</code>, both users would be returned since the first documents <code>firstName</code> is bob, and the last users <code>lastName</code> contains <code>bob</code>. If <code>bob j</code> was the search term, just the first document would be returned since if both names are combine, it equals <code>Bob Jerry</code> which matches the search term.</p>
  
  <p>I tried creating a basic <code>aggregate</code> to concatenate the names and then make a match, although Mongoose kept throwing me an error of: <code>Arguments must be aggregate pipeline operators</code>.</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>User.aggregate({
      $project: { "name" : { $concat : [ "$firstName", " ", "$lastName" ] } },
      $match: {"name": {$regex: "/bob j/i"}}
  }).exec(function(err, results) {
      ...
  });
  </code></pre>