Skip to content

FindOperations

Interface grouping MongoDB operations allowing to search for information.

Inheritors

Properties

context

Functions

find

abstract fun find(): MongoIterable<Document>

Finds all documents in this collection.

External resources

abstract fun find(options: FindOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit): MongoIterable<Document>

Finds all documents in this collection that satisfy filter.

If multiple predicates are specified, an and operator is implied.

Example

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

collection.find {
    User::name eq "foo"
    User::age eq 10
}

External resources

See also

  • findOne: When only one result is expected.

findOne

open suspend fun findOne(options: FindOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit): Document?

Finds a document in this collection that satisfies filter.

If multiple predicates are specified, and and operator is implied.

This function doesn't check that there is exactly one value in the collection. It simply returns the first matching document it finds.

Example

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

collection.findOne {
    User::name eq "foo"
    User::age eq 10
}

See also

  • find: When multiple results are expected.