title: using $$ROOT inside Spring Data Mongodb for retrieving whole document
body: <p>using mongodb shell, I am able to perform an aggregation query that retrieves the whole document.
  In order to do that I use the $$ROOT variable.</p>
  
  <pre><code>db.reservations.aggregate([
     { $match : { hotelCode : "0360" } },
     { $sort : { confirmationNumber : -1 , timestamp: -1 } },
     { $group : {
         _id : "$confirmationNumber",
         timestamp :{$first : "$timestamp"},
         fullDocument :{$first : "$$ROOT"}
     }}
  ])
  </code></pre>
  
  <p>It retrieves objects whose content is confirmationNumber, timestamp, fullDocument.
  fullDocument is the whole document. </p>
  
  <p>I am wondering if it is possible to do the same with Spring-Data and the aggregation framework.</p>
  
  <p>My java code is:</p>
  
  <pre><code>TypedAggregation&lt;ReservationImage&gt; aggregation = newAggregation(
     ReservationImage.class,
     match(where("hotelCode").is(hotelCode)),
     sort(Direction.DESC,"confirmationNumber","timestamp"),
     group("confirmationNumber").
       first("timestamp").as("timestamp").
       first("$$ROOT").as("reservationImage"));
    List&lt;myClass&gt; items = mongoTemplate.aggregate(
      aggregation, 
      myClass.class).getMappedResults();
  </code></pre>
  
  <p>the error is :
  org.springframework.data.mapping.PropertyReferenceException: No property $$ found for type myClass</p>
  
  <p>Do you have any ideas?</p>
  
  <p>Thanks.</p>