sql >> Base de Datos >  >> NoSQL >> MongoDB

grupo de mongodb de datos de primavera por

Cambia tu TypedAggregation parte a continuación y agregue students campo a StudentResults

 TypedAggregation<Student> studentAggregation = Aggregation.newAggregation(Student.class,
               Aggregation.group("firstName").
               push("$$ROOT").as("students"));

$$ROOT enviará todo el documento.

Actualización:

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