MongoDB request DSL • opensavvy.ktmongo.dsl.command • BulkWrite • replaceOne
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¶
-
BulkWrite.updateOneUpdate an existing document. -
BulkWrite.repsertOneReplace a document, or insert it if it doesn't exist.