plusAssign

open operator fun <V : Number> Field<T, V>.plusAssign(amount: V)(source)
open operator fun <V : Number> KProperty1<T, V>.plusAssign(amount: V)(source)

Increments a field by the specified amount.

amount may be negative, in which case the field is decremented.

If the field doesn't exist (either the document doesn't have it, or the operation is an upsert and a new document is created), the field is created with an initial value of amount.

Use of this operator with a field with a null value will generate an error.

Example

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

// It's the new year!
collection.updateMany {
User::age += 1
}

External resources