findAsFlow

fun <T : Any> MongoCollection<T>.findAsFlow(query: Bson): Flow<T>

Finds documents in a MongoDB collection that match the specified BSON query and returns them as a flow.

Return

A flow of documents that match the specified BSON query.

Example usage:

val collection = // new MongoCollection<Document>
val query = Filters.eq("field", "value")
val resultsFlow = collection.findAsFlow(query)
resultsFlow.collect { document -> println("Found document: $document") }

Parameters

query

The BSON query to filter the documents.


fun <T : Any> MongoCollection<T>.findAsFlow(): Flow<T>

Finds all documents in a MongoDB collection and returns them as a flow.

Return

A flow of all documents in the collection.

Example usage:

val collection = // new MongoCollection<Document>
val resultsFlow = collection.findAsFlow()
resultsFlow.collect { document -> println("Found document: $document") }