title: using $regex in mongodb aggregation framework in $group
body: <p>Consider the following example:</p>
  
  <pre class="lang-js prettyprint-override"><code>db.article.aggregate(
    { $group : {
        _id : "$author",
        docsPerAuthor : { $sum : 1 },
        viewsPerAuthor : { $sum : "$pageViews" }
    }}
  );
  </code></pre>
  
  <p>This groups by the author field and computes two fields.</p>
  
  <p>I have values for $author = FirstName_LastName.
  Now instead of grouping by $author, I want to group by all authors who share the same LastName.</p>
  
  <p>I tried $regex to group by all matching strings after the '_'</p>
  
  <pre class="lang-js prettyprint-override"><code>$author.match(/_[a-zA-Z0-9]+$/)
  
  db.article.aggregate(
    { $group : {
        _id : "$author".match(/_[a-zA-Z0-9]+$/),
        docsPerAuthor : { $sum : 1 },
        viewsPerAuthor : { $sum : "$pageViews" }
    }}
  );
  
  also tried the following:
  
   db.article.aggregate(
    { $group : {
        _id : {$author: {$regex: /_[a-zA-Z0-9]+$/}},
        docsPerAuthor : { $sum : 1 },
        viewsPerAuthor : { $sum : "$pageViews" }
    }}
  );
  </code></pre>