insertMany

fun <T> MongoCollection<T>.insertMany(flow: Flow<T>, concurrency: Int = 1, options: InsertManyOptions = InsertManyOptions(), groupStrategy: GroupStrategy = GroupStrategy.TimeWindow(10, 500.milliseconds)): Flow<InsertManyResult>

Inserts many documents into a MongoDB collection using a flow of documents, batching them by the provided chunkStrategy.

Return

A flow of InsertManyResult objects.

Example usage:

val collection = // new MongoCollection<Document>
val documentsFlow = flowOf(Document("field" to "value"))
collection.insertMany(documentsFlow).collect { result -> println("Documents inserted: ${result.insertedIds.size}") }

Parameters

flow

The flow of documents to insert.

concurrency

The concurrency for this operation. Defaults to 1.

options

The InsertManyOptions to use when inserting the documents. Defaults to InsertManyOptions().

groupStrategy

The strategy for chunking the documents. Defaults to ChunkStrategy.TimeWindow(10, 500.milliseconds).