MongoDB request DSL • opensavvy.ktmongo.dsl.command • BulkWrite • insertMany
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¶
-
BulkWrite.insertOne
Insert a single document. -
BulkWrite.updateMany
Update multiple documents.
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¶
-
BulkWrite.insertOne
Insert a single document. -
BulkWrite.updateMany
Update multiple documents.