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是接收类中的字段

相关文章:

  • 2021-06-08
  • 2021-10-26
  • 2021-11-13
  • 2021-10-19
  • 2021-06-11
  • 2021-06-11
  • 2021-05-17
  • 2021-04-06
猜你喜欢
  • 2021-12-03
  • 2021-10-15
  • 2021-05-20
  • 2021-09-29
  • 2021-05-23
  • 2021-07-11
  • 2021-06-23
  • 2021-10-24
相关资源
相似解决方案