【发布时间】:2017-06-03 00:41:49
【问题描述】:
我想使用 MongoDB 的 Spring 数据对 MongoDB 中的多个字段进行排序。目前我正在尝试使用聚合来实现这一点:
Aggregation agg = newAggregation(
match(Criteria.where("userId").is(userId)),
sort(Sort.Direction.DESC, "type", "createdDate"),
);
AggregationResults<MyBean> results = mongoOperations.aggregate(agg, MyBean.class, MyBean.class);
当我这样做时,它会在 type 和 createdDate 上排序 DESC 订单。但我想要DESC 上的type 和ASC 上的createdDate。
我试过了,
sort(Sort.Direction.DESC, "type");
sort(Sort.Direction.ASC, "createdDate");
但这只是在createdDate上排序。
【问题讨论】:
标签: java mongodb mongodb-query aggregation-framework spring-data-mongodb