将您的
TypedAggregation零件更改为下面,并添加
students字段到
StudentResults
TypedAggregation<Student> studentAggregation = Aggregation.newAggregation(Student.class, Aggregation.group("firstName"). push("$$ROOT").as("students"));$$ ROOT将推送整个文档。
更新:
TypedAggregation<Student> studentAggregation = Aggregation.newAggregation(Student.class, Aggregation.group("firstName"). push(new BasicDBObject ("_id", "$_id").append ("firstName", "$firstName").append ("lastName", "$lastName")).as("students"));


