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<MyClass> results = mongoTemplate.aggregate(agg, MyClass.class);
List<MyClass> myList = results.getMappedResults();
全文毕
欢迎关注微信公众号:Javall咖啡屋
每天更新各种互联网技术(前后端、数据库、中间件、设计模式、数据结构、算法)学习心得体会