直接上代码(字符串版本)
Criteria criteriaTwo = Criteria.where("isDelete").is(0).and("isAble").is(1);
Aggregation agg = Aggregation.newAggregation(
match(criteriaTwo),
Aggregation.project("releaseTime").andExpression("releaseTime")
.substring(0,10).as("times"),
Aggregation.group("times").count().as("count"));
AggregationResults<Map> aMap = mongoTemplateApi.aggregate(agg,AInfo.class,Map.class);
直接上代码(日期版本)
Criteria criteriaTwo = Criteria.where("isDelete").is(0).and("isAble").is(1);
Aggregation agg = Aggregation.newAggregation(
match(criteriaTwo),
Aggregation.project("isTure")
.and(DateOperators.DateToString.dateOf( "orderTime" )
.toString("%Y-%m-%d")).as("times"),
Aggregation.group("times").count().as("count"));
AggregationResults<Map> aMap = mongoTemplateApi.aggregate(agg,AInfo.class,Map.class);
代码解释:
$project - 可以重构数据
$match - 可以实现类似query的功能
$limit - 限制返回个数
$group - 统计操作, 还提供了一系列子命令
$sort - 排序
原文链接:https://blog.csdn.net/sinat_30735061/article/details/103520437
原文链接:https://blog.csdn.net/cwh_zy/article/details/91957170