replace

fun <T : Any> MongoCollection<T>.replace(flow: Flow<T>, filter: Bson, concurrency: Int = 1): Flow<UpdateResult>

Replaces documents in a MongoDB collection using a flow of documents and a filter.

Return

A flow of UpdateResult objects.

Example usage:

val collection = // new MongoCollection<Document>
val filter = Filters.eq("field", "value")
val replacementsFlow = flowOf(Document("field" to "newValue"))
collection.replace(replacementsFlow, filter).collect { result -> println("Documents replaced: ${result.modifiedCount}") }

Parameters

flow

The flow of documents to replace.

filter

The BSON filter to apply when replacing documents.

concurrency

The concurrency for this operation. Defaults to 1.


fun <T : Any> MongoCollection<T>.replace(flow: Flow<Pair<Bson, T>>, concurrency: Int = 1): Flow<UpdateResult>

Replaces documents in a MongoDB collection using a flow of pairs containing a filter and a document.

Return

A flow of UpdateResult objects.

Example usage:

val collection = // new MongoCollection<Document>
val filter = Filters.eq("field", "value")
val replacementsFlow = flowOf(filter to Document("field" to "newValue"))
collection.replace(replacementsFlow).collect { result -> println("Documents replaced: ${result.modifiedCount}") }

Parameters

flow

The flow of pairs containing a filter and a document.

concurrency

The concurrency for this operation. Defaults to 1.