insert

fun <T : Any> MongoCollection<T>.insert(flow: Flow<T>, concurrency: Int = 1): Flow<InsertOneResult>

Inserts documents into a MongoDB collection using a flow of documents.

Return

A flow of InsertOneResult objects.

Example usage:

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

Parameters

flow

The flow of documents to insert.

concurrency

The concurrency for this operation. Defaults to 1.