Skip to content

MongoDB driver for Kotlin (synchronous)opensavvy.ktmongo.sync.operationsInsertOperationsinsertOne

insertOne

abstract fun insertOne(document: Document, options: <Document>.() -> Unit = {})

Inserts a document.

Example

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

collection.insertOne(User(name = "Bob", age = 18))

Note that insertOne ignores filtered collection. That is, insertOne on a filtered collection behaves exactly the same as the same insertOne on the underlying real collection.

External resources

See also