mongoTemplate Aggregation first

       Aggregation managerSum = Aggregation.newAggregation(
                Aggregation.group("_id").first("by_user").as("by_user").first("title").as("title")
                        .count().as("jiShu")
        );

显示结果

Runoob(id=5ee97bd3fd4200000c000618, title=MongoDB Overview, description=null, by_user=runoob.com1, url=null, tags=null, likes=null, jiShu=1)
Runoob(id=5ee97bd3fd4200000c00061a, title=Neo4j Overview, description=null, by_user=runoob.com2, url=null, tags=null, likes=null, jiShu=1)
Runoob(id=5f0eb8a55f07000038007f94, title=runoob.com2, description=null, by_user=runoob.com2, url=null, tags=null, likes=null, jiShu=1)
Runoob(id=5ee97bd3fd4200000c000619, title=NoSQL Overview, description=null, by_user=runoob.com, url=null, tags=null, likes=null, jiShu=1)

没有加first在结果中就没有显示

first("title")//此title是数据中的字段
as("title")//此title是接收类中的字段
原文地址:https://www.cnblogs.com/lovetl/p/13306268.html