簡體   English   中英

在 Spring Data MongoDB 中使用聚合進行更新

[英]Use aggregation for update in Spring Data MongoDB

有沒有辦法在 Spring Data MongoDB更新查詢中使用聚合管道

假設,我想為沒有lastName用戶將firstName值設置為fullName字段。 本機查詢如下所示:

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"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM