title: Group aggregation using spring data mongodb
body: <p>I tried to write a group aggregation query using the year value from a date object as a key, but for some reason I'm getting this exception. </p>
  
  <pre><code>org.springframework.data.mapping.PropertyReferenceException: No property year(invoiceDate)
  </code></pre>
  
  <p>Here is the mongo query which I'm trying to replicate:</p>
  
  <pre><code>db.collection.aggregate([
     {
       $match:
       {
         "status": "Active"
       }
     },
     {
       $group:
       {
        "_id":{$year:"$invoiceDate"}
       }
    },
    {
      $sort:
      {
        "_id" : -1
      }
    }
  ])
  </code></pre>
  
  <p>And this is my Java implementation:</p>
  
  <pre><code>Aggregation aggregation = Aggregation.newAggregation(
      match(new Criteria().andOperator(criteria())),
      Aggregation.group("year(invoiceDate)")
  ).withOptions(newAggregationOptions().allowDiskUse(true).build());
  </code></pre>
  
  <p>I also didn't find a way how I can apply the sorting on the results from the grouping.</p>