findOneAndUpdate

abstract suspend fun findOneAndUpdate(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpdateQuery<Document>.() -> Unit): Document?(source)

Updates one element that matches filter according to update and returns it, atomically.

Example

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

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

External resources

Parameters

filter

Optional filter to select which document is updated. If no filter is specified, the first document found is updated.

See also

Update more than one document.

Do not return the value.