deleteOne

suspend fun deleteOne(filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult

Removes at most one document from the collection that matches the given filter.

If no documents match, the collection is not modified.

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

Return

the result of the remove one operation

Parameters

filter

the query filter to apply the delete operation

options

the options to apply to the delete operation

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 deleteOne(clientSession: ClientSession, filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult

Removes at most one document from the collection that matches the given filter.

If no documents match, the collection is not modified.

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

Return

the result of the remove one operation

Parameters

clientSession

the client session with which to associate this operation

filter

the query filter to apply the delete operation

options

the options to apply to the delete operation

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