setOnInsert

abstract infix fun <V> Field<T, V>.setOnInsert(value: V)(source)
open infix fun <V> KProperty1<T, V>.setOnInsert(value: V)(source)

If an upsert operation results in an insert of a document, then this operator assigns the specified value to the field. If the update operation does not result in an insert, this operator does nothing.

Example

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

collection.filter {
User::name eq "foo"
}.upsertOne {
User::age setOnInsert 18
}

External resources

See also

Always set the value.