ProjectionOperation projection = Aggregation.project()
.and(ConditionalOperators.when(Criteria.where("flag").is(true)).then("是").otherwise(
ConditionalOperators.when(Criteria.where("flag").is(false)).then("否").otherwise("未标记")
)).as("flag");
Aggregation aggregation = Aggregation.newAggregation(projection);
List<JSONObject> result = mongoTemplate.aggregate(aggregation, "test1", JSONObject.class).getMappedResults();
for (JSONObject demo : result) {
System.out.println("demo = " + demo);
}
mongodb 聚合函数-ProjectionOperation
最新推荐文章于 2024-05-30 09:26:27 发布