Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryUpdateQuerysetIf

setIf

open fun <V> Field<T, V>.setIf(condition: Boolean, value: V)

Replaces the value of a field with the specified value, if condition is true.

If condition is false, this operator does nothing.

Example

class User(
    val name: String?,
    val age: Int,
)

collection.filter {
    User::name eq "foo"
}.updateMany {
    User::age.setIf(someComplexOperation, 18)
}

External resources

See also

open fun <V> KProperty1<T, V>.setIf(condition: Boolean, value: V)

Replaces the value of a field with the specified value, if condition is true.

If condition is false, this operator does nothing.

Example

class User(
    val name: String?,
    val age: Int,
)

collection.filter {
    User::name eq "foo"
}.updateMany {
    User::age.setIf(someComplexOperation, 18)
}

External resources

See also