MongoDB request DSL • opensavvy.ktmongo.dsl.command • BulkWrite • updateOne
updateOne¶
fun updateOne(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpdateQuery<Document>.() -> Unit)
Updates a single document that matches filter
according to update
.
If multiple documents match filter
, only the first one found is updated.
Example¶
class User(
val name: String,
val age: Int,
)
collection.bulkWrite {
updateOne(
filter = { User::name eq "Patrick" },
update = {
User::age set 15
}
)
}
External resources¶
See also¶
-
BulkWrite.updateMany
Update multiple documents. -
BulkWrite.insertOne
Create a new document. -
BulkWrite.upsertOne
Create a document if none are found.