MongoDB request DSL • opensavvy.ktmongo.dsl.query • UpdateQuery • inc
inc¶
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 inc 1
}
External resources¶
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 inc 1
}