Mongo es difícil de usar, principalmente porque no está acostumbrado a escribir muchas palabras
La documentación está muy bien escrita.
https://docs.mongodb.com/manual/reference/aggregation-variables/#agg-system-variables
https://docs.mongodb.com/manual/reference/operator/aggregation/sort/index.html
https://docs.mongodb.com/manual/reference/operator/aggregation/group/index.html
Este articulo esta bien.
https://www.jianshu.com/p/206f036bdfc5
Correspondiente a mongtemplate en springboot, está escrito así
Esto está muy bien escrito
https://kb.objectrocket.com/mongo-db/mongodb-group-by-multiple-fields-using-aggregation-function-464
db.sales.aggregate ( [ {$ sort: {item: -1, date: -1 }}, { $ group: { _id: "$ item" , firstSalesDate: {$ first: "$ date" }, firstId: {$ first: "$ _id" }, firstRoot: {$ first: "$$ ROOT" }, } } ] )
Criterio criterio = Criterio.where ("xxx"). Is ("xxxx"). Y ("xxx"). Is (xxx);
Aggregation aggregation = Aggregation.newAggregation ( Aggregation.match (criterios), Aggregation.sort (Sort.Direction.ASC, "createTime" ), Aggregation.group ( "xx", "xx" ) .first ( "$ id"). as ("xx" ) .first ( "$ xxx"). as ("xx" ) .first ( "$ xxx"). as ("" xx " ) .first ( " $ xxxx "). as (" .first ( "$ xxxx"). as ("xx" ) );
La mayor dificultad es que $ _id se llama $ id en mongotemplate, less _ y Aggregation.ROOT, Aggregation.CURRENT