1,746
社区成员
发帖
与我相关
我的任务
分享
public List<CountIdDTO> listGroupCount(String groupField, String collectionName) {
Aggregation agg = Aggregation.newAggregation(Aggregation.group(groupField).count().as("count"),
Aggregation.project("count").and(groupField).as("objectId"));
AggregationResults<CountIdDTO> results = mongoTemplate.aggregate(agg, collectionName, CountIdDTO.class);
List<CountIdDTO> countIdDTO = results.getMappedResults();
return countIdDTO;
}
我写的代码是这样,测试错误