MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

spring data mongodb raggruppa per

Modifica la tua TypedAggregation parte in basso e aggiungi students campo a StudentResults

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

$$ROOT spingerà l'intero documento.

Aggiornamento:

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