spring-data-mongo 聚合分析时的条件操作($cond)

example

import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
import static org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond.*;
import org.springframework.data.mongodb.core.query.Criteria;

Cond condOperation = ConditionalOperators.when(Criteria.where("start").is("EARLY"))
                                    .thenValueOf("deltastart.start")
                                    .otherwise("deltastart.end");

Aggregation agg = newAggregation(project().and(condOperation).as("start"));
AggregationResults results = mongoTemplate.aggregate(agg, MyClass.class); 
List myList = results.getMappedResults();

全文毕

欢迎关注微信公众号:Javall咖啡屋
每天更新各种互联网技术(前后端、数据库、中间件、设计模式、数据结构、算法)学习心得体会


你可能感兴趣的:(spring-data-mongo 聚合分析时的条件操作($cond))