MongoDB request DSL • opensavvy.ktmongo.dsl.aggregation.operators • ConditionalValueOperators • switch
switch¶
Selects one value based on multiple conditions.
Example¶
class User(
val name: String,
val score: Int,
val role: String,
val bonus: Int?,
)
users.updateManyWithPipeline {
set {
User::bonus set switch(
of(User::role) eq of("GUEST") to of(5),
of(User::role) eq of("EMPLOYEE") to of(6),
of(User::role) eq of("ADMIN") to of(7),
default = of(-1)
)
}
}
External resources¶
See also¶
ConditionalValueOperators.cond
Specify a single condition.