先导入mongo数据库所需的jar包
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
T.class为mongo数据库实体类
使用mongoTemplate实现
TypedAggregationnoRepeated = Aggregation.newAggregation( T.class,//数据库的实体类 Aggregation.match(Criteria.where(数据库字段).is(待满足的条件).and(数据库字段).is(待满足的条件)),//匹配的规则,先获取数据中将满足条件的警报 Aggregation.group(分类的字段, 分类的字段, ...)//按哪些字段进行分类 .first(数据库字段).as(数据库字段)//需要的字段名 .first(数据库字段).as(数据库字段)//需要的字段名 .first(数据库字段).as(数据库字段)//需要的字段名 ); List results= mongoTemplate.aggregate(noRepeated, T.class).getMappedResults();



