Skip to content

MongoDB driver for Kotlin (synchronous)opensavvy.ktmongo.sync.operationsUpdateOperationsupdateMany

updateMany

abstract fun updateMany(options: <Document>.() -> Unit = {}, filter: <Document>.() -> Unit = {}, update: <Document>.() -> Unit)

Updates all documents that match filter according to update.

Example

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

collection.updateMany(
    filter = {
        User::name eq "Patrick"
    },
    update = {
        User::age set 15
    },
)

Using filtered collections

The following code is equivalent:

collection.filter {
    User::name eq "Patrick"
}.updateMany {
    User::age set 15
}

To learn more, see filter.

External resources

Parameters

filter

Optional filter to select which documents are updated. If no filter is specified, all documents are updated.

See also