Skip to content

MongoDB driver for Kotlin (coroutines)opensavvy.ktmongo.coroutinesJvmMongoCollectioncount

count

open suspend override fun count(): Long

Counts how many documents exist in the collection.

External resources

See also

open suspend override fun count(options: CountOptions<Document>.() -> Unit, predicate: FilterQuery<Document>.() -> Unit): Long

Counts how many documents match predicate in the collection.

Example

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

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

External resources