findOneAndUpdate

suspend fun <T : Any> MongoCollection<T>.findOneAndUpdate(filter: Bson, update: T, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?

Atomically find a document and update it with the not null properties of update.

Return

the document that was updated (before or after the update, depending of the options)

Parameters

filter

a document describing the query filter

update

the object used to build the update

options

the options to apply to the operation


suspend fun <T : Any> MongoCollection<T>.findOneAndUpdate(clientSession: ClientSession, filter: Bson, update: T, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?

Atomically find a document and update it with the not null properties of update.

Return

the document that was updated (before or after the update, depending of the options)

Parameters

clientSession

the client session with which to associate this operation

filter

a document describing the query filter

update

the object used to build the update

options

the options to apply to the operation


suspend fun <T : Any> MongoCollection<T>.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?

Atomically find a document and update it.

Return

the document that was updated. Depending on the value of the returnOriginal property, this will either be the document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be returned

Parameters

filter

a document describing the query filter, which may not be null.

update

a document describing the update, which may not be null. The update to apply must include only update operators.

options

the options to apply to the operation


suspend fun <T : Any> MongoCollection<T>.findOneAndUpdate(clientSession: ClientSession, filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?

Atomically find a document and update it.

Return

the document that was updated. Depending on the value of the returnOriginal property, this will either be the document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be returned

Parameters

clientSession

the client session with which to associate this operation

filter

a document describing the query filter, which may not be null.

update

a document describing the update, which may not be null. The update to apply must include only update operators.

options

the options to apply to the operation