insertOne

suspend fun insertOne(document: T, options: InsertOneOptions = InsertOneOptions()): InsertOneResult

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

Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.

Return

the insert one result

Parameters

document

the document to insert

options

the options to apply to the operation

Throws

MongoWriteException

if the write failed due to some specific write exception

MongoWriteConcernException

if the write failed due to being unable to fulfil the write concern

MongoCommandException

if the write failed due to a specific command exception

MongoException

if the write failed due some other failure


suspend fun insertOne(clientSession: ClientSession, document: T, options: InsertOneOptions = InsertOneOptions()): InsertOneResult

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

Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.

Return

the insert one result

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

MongoWriteException

if the write failed due to some specific write exception

MongoWriteConcernException

if the write failed due to being unable to fulfil the write concern

MongoCommandException

if the write failed due to a specific command exception

MongoException

if the write failed due some other failure