title: Spring data mongodb group aggregation object
body: <p>I'm trying to group a object based on a query with spring data and mongodb, that's what i do till now:</p>
  
  <p><strong>Mongodb data:</strong></p>
  
  <pre><code>{
   "_id" : ObjectId("58af31feef34aa45476d2be9"),
   "_class" : "my.model.Image",
   "file" : "0006000.jpg",
   "number" : "123",
   "mkdius" : "Fiscalization 432",
   "status" : "UNCOMPLETED",
   "createdAt" : ISODate("2017-02-23T16:03:26.612-03:00")
  },
  {
   "_id" : ObjectId("58af31feef34aa45476d2bf3"),
   "_class" : "my.model.Image",
   "file" : "9781.jpg",
   "number" : "987",
   "mkdius" : "Fiscalization 432",
   "status" : "UNCOMPLETED",
   "createdAt" : ISODate("2017-02-23 16:03:26.866-03:00")
  },
  {
   "_id" : ObjectId("58af31feef34aa45476d2bea"),
   "_class" : "my.model.Image",
   "file" : "00016.jpg",
   "number" : "432",
   "mkdius" : "Fiscalization 4154",
   "status" : "UNCOMPLETED",
   "createdAt" : ISODate("2017-02-23T16:03:26.835-03:00")
  }
  </code></pre>
  
  <p><strong>My aggregation function:</strong></p>
  
  <pre><code>Aggregation aggregation = Aggregation.newAggregation(
      Aggregation.match(Criteria.where("status").is(Status.UNCOMPLETED)), // Match
      Aggregation.group("mkdius").last("mkdius").as("mkdius").addToSet("id").as("imgsId"), // Grouping
      Aggregation.project("imgsId").and("cd").previousOperation()); // Projecting
  
  AggregationResults&lt;InitApp.result&gt; groupResults = this.mongoTemplate.aggregate(aggregation, Image.class, InitApp.result.class);
  
  groupResults.getMappedResults().forEach(System.out::println);
  </code></pre>
  
  <p><strong>Result that i got:</strong></p>
  
  <pre><code>InitApp.result(mkdius=Fiscalization 432, imgIds=[58af31feef34aa45476d2be9,58af31feef34aa45476d2bf3]
  
  InitApp.result(mkdius=Fiscalization 4154, imgIds=[58af31feef34aa45476d2bea]
  </code></pre>
  
  <p><strong>What i expect:</strong></p>
  
  <pre><code>InitApp.result(mkdius=Fiscalization 432, imgs=[{
   "_id" : ObjectId("58af31feef34aa45476d2be9"),
   "_class" : "my.model.Image",
   "file" : "0006000.jpg",
   "number" : "123",
   "mkdius" : "Fiscalization 432",
   "status" : "UNCOMPLETED",
   "createdAt" : ISODate("2017-02-23T16:03:26.612-03:00")
  },{
   "_id" : ObjectId("58af31feef34aa45476d2bf3"),
   "_class" : "my.model.Image",
   "file" : "9781.jpg",
   "number" : "987",
   "mkdius" : "Fiscalization 432",
   "status" : "UNCOMPLETED",
   "createdAt" : ISODate("2017-02-23 16:03:26.866-03:00")
  }]
  
  InitApp.result(cd=Fiscalization 4154, imgs=[{
   "_id" : ObjectId("58af31feef34aa45476d2bea"),
   "_class" : "my.model.Image",
   "file" : "00016.jpg",
   "number" : "432",
   "mkdius" : "Fiscalization 4154",
   "status" : "UNCOMPLETED",
   "createdAt" : ISODate("2017-02-23T16:03:26.835-03:00")
  }]
  </code></pre>
  
  <p>I don't know if it's possible to do, aggregate the data and put the current object in the response.</p>
  
  <p>Thanks.</p>