在Spring Data MongoDB 更新查询中是否可以使用aggregation pipeline?
假设,对于没有firstName
的用户,我想在fullName
字段中设置lastName
值。本机查询如下所示:
db.getCollection("users").update({lastName: ""}, [{ $set: { "fullName" : "$firstName" } }])
使用Spring Data是否可行?
[AggregationUpdate
将成为Spring Data MongoDB 3.0的一部分。
AggregationUpdate update = AggregationUpdate.update()
.set("average").toValue(ArithmeticOperators.valueOf("tests").avg())
.set("grade").toValue(
ConditionalOperators.switchCases(
CaseOperator.when(Gte.valueOf("average").greaterThanEqualToValue(90)).then("A"),
CaseOperator.when(Gte.valueOf("average").greaterThanEqualToValue(80)).then("B"),
CaseOperator.when(Gte.valueOf("average").greaterThanEqualToValue(70)).then("C"),
CaseOperator.when(Gte.valueOf("average").greaterThanEqualToValue(60)).then("D"))
.defaultTo("F"));