Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.commandBulkWritereplaceOne

replaceOne

fun replaceOne(options: ReplaceOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, document: Document)

Replaces a document that matches filter by document.

If multiple documents match filter, only the first one found is updated.

Example

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

collection.bulkWrite {
    replaceOne(
        filter = { User::name eq "Patrick" },
        document = User("Bob", 15)
    )
}

External resources

See also