MongoDB driver for Kotlin (coroutines) • opensavvy.ktmongo.coroutines.operations • UpdateOperations • findOneAndUpdate
findOneAndUpdate¶
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
},
)
Using filtered collections¶
The following code is equivalent:
To learn more, see filter
.
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¶
-
UpdateOperations.updateMany
Update more than one document. -
UpdateOperations.updateOne
Do not return the value.