insertOne

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

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

Throws

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


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

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

Throws

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