kmongo / org.litote.kmongo / com.mongodb.client.MongoCollection / insertOne

insertOne

fun <reified T : Any> MongoCollection<T>.insertOne(document: String, options: InsertOneOptions = InsertOneOptions()): InsertOneResult! (source)

Inserts the provided document. If the document is missing an identifier, the driver should generate one.

Parameters

document - the document to insert

options - the options to apply to the operation

Exceptions

com.mongodb.MongoWriteException - if the write failed due some other failure specific to the insert command

com.mongodb.MongoWriteConcernException - if the write failed due being unable to fulfil the write concern

com.mongodb.MongoCommandException - if the write failed due to document validation reasons

com.mongodb.MongoException - if the write failed due some other failure

fun <reified T : Any> MongoCollection<T>.insertOne(clientSession: ClientSession, document: String, options: InsertOneOptions = InsertOneOptions()): InsertOneResult! (source)

Inserts the provided document. If the document is missing an identifier, the driver should generate one.

Parameters

clientSession - the client session with which to associate this operation

document - the document to insert

options - the options to apply to the operation

Exceptions

com.mongodb.MongoWriteException - if the write failed due some other failure specific to the insert command

com.mongodb.MongoWriteConcernException - if the write failed due being unable to fulfil the write concern

com.mongodb.MongoCommandException - if the write failed due to document validation reasons

com.mongodb.MongoException - if the write failed due some other failure