kmongo / org.litote.kmongo / com.mongodb.client.MongoCollection / replaceOne

replaceOne

fun <reified T : Any> MongoCollection<T>.replaceOne(replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult (source)

Replace a document in the collection according to the specified arguments.

Parameters

replacement - the document to replace - must have an non null id

options - the options to apply to the replace operation

Exceptions

com.mongodb.MongoWriteException - if the write failed due some other failure specific to the update command

com.mongodb.MongoWriteConcernException - if the write failed due being unable to fulfil the write concern

com.mongodb.MongoException - if the write failed due some other failure

Return
the result of the replace one operation

fun <T : Any> MongoCollection<T>.replaceOne(filter: String, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult (source)

Replace a document in the collection according to the specified arguments.

Parameters

filter - the query filter to apply to the replace operation

replacement - the replacement document

options - the options to apply to the replace operation

Exceptions

com.mongodb.MongoWriteException - if the write failed due some other failure specific to the update command

com.mongodb.MongoWriteConcernException - if the write failed due being unable to fulfil the write concern

com.mongodb.MongoException - if the write failed due some other failure

Return
the result of the replace one operation

fun <reified T : Any> MongoCollection<T>.replaceOne(clientSession: ClientSession, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult (source)

Replace a document in the collection according to the specified arguments.

Parameters

clientSession - the client session with which to associate this operation

replacement - the document to replace - must have an non null id

options - the options to apply to the replace operation

Exceptions

com.mongodb.MongoWriteException - if the write failed due some other failure specific to the update command

com.mongodb.MongoWriteConcernException - if the write failed due being unable to fulfil the write concern

com.mongodb.MongoException - if the write failed due some other failure

Return
the result of the replace one operation

fun <T : Any> MongoCollection<T>.replaceOne(clientSession: ClientSession, filter: String, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult (source)

Replace a document in the collection according to the specified arguments.

Parameters

clientSession - the client session with which to associate this operation

filter - the query filter to apply to the replace operation

replacement - the replacement document

options - the options to apply to the replace operation

Exceptions

com.mongodb.MongoWriteException - if the write failed due some other failure specific to the update command

com.mongodb.MongoWriteConcernException - if the write failed due being unable to fulfil the write concern

com.mongodb.MongoException - if the write failed due some other failure

Return
the result of the replace one operation