【发布时间】:2025-11-25 07:00:01
【问题描述】:
我有一个映射 Map filterParams,它的键值对将成为 Criteria 的一部分。如何创建 Criteria 对象。
之前我使用的是 Query.addCriteria。但是现在我想要一个条件对象,因为我需要将它传递给 mongo 中的 Aggregation.match()。
filterParams.entrySet().forEach(e -> query.addCriteria(criteria.where(e.getKey()).is(e.getValue())));
Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(criteria ),Aggregation.group("property_type.name").count().as("count"),
Aggregation.project("property_type").andExclude("_id"));
【问题讨论】:
标签: spring mongodb spring-boot criteria