Skip to content

FindOperations

The different MongoDB operations related to finding documents.

Inheritors

Properties

context

abstract val context: BsonContext

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

For more information, see BsonContext.

factory

abstract val factory: BsonFactory

The BsonFactory used to serialize and deserialize values.

This property stores all serialization configurations and allows creating custom BSON objects.

For more information, see BsonFactory.

objectIdGenerator

The algorithm used to generate new ObjectId instances.

For more information, see ObjectIdGenerator.

propertyNameStrategy

The strategy used to convert property names to BSON document keys.

For more information, see PropertyNameStrategy.

Functions

find

abstract fun find(): MongoIterable<Document>

Finds all documents in this collection.

External resources

See also

  • find: When a filter is needed.
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 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, an 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.