Skip to content

DeleteOperations

The different MongoDB operations related to deleting documents.

Inheritors

Properties

context

The full BSON configuration, used by the DSL to generate queries.

For more information, see BsonContext.

Functions

deleteMany

abstract suspend fun deleteMany(options: DeleteManyOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit)

Deletes all documents that match filter.

Example

class User(
    val name: String,
    val age: Int
)

collection.deleteMany {
    User::age lt 18
}

External resources

deleteOne

abstract suspend fun deleteOne(options: DeleteOneOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit)

Deletes the first document found that matches filter.

Example

class User(
    val name: String,
    val age: Int
)

collection.deleteOne {
    User::name eq "Bob"
}

External resources