Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.commandBulkWriteinsertMany

insertMany

fun insertMany(documents: Iterable<Document>, options: InsertOneOptions<Document>.() -> Unit = {})

Inserts multiple documents in a single operation.

Example

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

collection.bulkWrite {
    insertMany(listOf(User(name = "Bob", age = 18), User(name = "Alice", age = 17)))
}

External resources

See also

fun insertMany(vararg documents: Document, options: InsertOneOptions<Document>.() -> Unit = {})

Inserts multiple documents in a single operation.

Example

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

collection.bulkWrite {
    insertMany(User(name = "Bob", age = 18), User(name = "Alice", age = 17))
}

External resources

See also