title: Split a string during MongoDB aggregate
body: <p>Currently, I have just <code>fullname</code> stored in the <code>User</code> collection in MongoDB. I'd like to run a report that splits the first and last name so for now I'm trying to run an aggregate and split the string when a whitespace is found.</p>
  
  <p>Here is what I have now, but I'd like to replace the hard coded end position with a variable based on where whitespace is found. Is this possible in an aggregate pipeline?</p>
  
  <pre><code>db.users.aggregate([{ 
      $project : {
          fullname:{ $toUpper:"$fullname" },
          first: { $substr: [ "$fullname", 0, 2 ]}, _id:0 }
      }, { $sort : { fullname : 1 }
  }]);
  </code></pre>