title: Laravel mongoDB groupBy - ERROR: Unrecognized expression '$last'
body: <p>My below code is producing an error. If the <strong>groupBy</strong> is removed it works fine. But I only need to get distinct values for common_id. How can i solve this issue?</p>
  
  <pre><code>MasterAffiliateProductMappingMongo::select('_id', 'our_product_id')
                                     -&gt;where('top_deal', '=', 'true')
                                     -&gt;orderBy('srp', 'asc')
                                     -&gt;groupBy('common_id')
                                     -&gt;get();
  </code></pre>
  
  <blockquote>
    <p>Error:   [MongoDB\Driver\Exception\RuntimeException]     Unrecognized
    expression '$last'</p>
  </blockquote>
  
  <p>MongoDocument Example:</p>
  
  <pre><code>{
      "_id" : ObjectId("5911af8209ed4456d069b1d1"),
      "product_id" : "MOBDRYWXFKNPZVG6",
      "our_product_id" : "5948e0dca6bc725adb35af2e",
      "mrp" : 0.0,
      "srp" : 500.0,
      "ID" : "5911af8209ed4456d069b1d1",
      "common_id" : ObjectId("5911af8209ed4456d069b1d1"),
      "top_deal" : "true"
  }
  </code></pre>
  
  <p>Error Log: </p>
  
  <blockquote>
    <p>[2017-06-28 12:19:46] lumen.ERROR: exception
    'MongoDB\Driver\Exception\RuntimeException' with message 'Unrecognized
    expression '$last'' in
    /var/www/html/PaymetryService4/vendor/mongodb/mongodb/src/Operation/Aggregate.php:219</p>
  </blockquote>