replaceOne

suspend fun replaceOne(filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult

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

Use this method to replace a document using the specified replacement argument. To update the document with update operators, use the corresponding updateOne method.

Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.

Return

the result of the replace one operation

Since

3.6

Parameters

filter

the query filter to apply the replace operation

replacement

the replacement document

options

the options to apply to the replace operation

See also

Throws

MongoWriteException

if the write failed due to some specific write exception

MongoWriteConcernException

if the write failed due to being unable to fulfil the write concern

MongoCommandException

if the write failed due to a specific command exception

MongoException

if the write failed due some other failure


suspend fun replaceOne(clientSession: ClientSession, filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult

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

Use this method to replace a document using the specified replacement argument. To update the document with update operators, use the corresponding updateOne method.

Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.

Return

the result of the replace one operation

Since

3.6

Parameters

clientSession

the client session with which to associate this operation

filter

the query filter to apply the replace operation

replacement

the replacement document

options

the options to apply to the replace operation

See also

Throws

MongoWriteException

if the write failed due to some specific write exception

MongoWriteConcernException

if the write failed due to being unable to fulfil the write concern

MongoCommandException

if the write failed due to a specific command exception

MongoException

if the write failed due some other failure