MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

spring data mongodb group por


Altere sua TypedAggregation parte abaixo e adicione students campo para StudentResults
 TypedAggregation<Student> studentAggregation = Aggregation.newAggregation(Student.class,
               Aggregation.group("firstName").
               push("$$ROOT").as("students"));

$$ROOT fará o push de todo o documento.

Atualizar:
TypedAggregation<Student> studentAggregation = Aggregation.newAggregation(Student.class,
              Aggregation.group("firstName").
                 push(new BasicDBObject
                       ("_id", "$_id").append
                       ("firstName", "$firstName").append
                       ("lastName", "$lastName")).as("students"));