save

suspend fun <T : Any> MongoCollection<T>.save(document: T): UpdateResult?

Save the document. If the document has no id field, or if the document has a null id value, insert the document. Otherwise, call replaceOneById with upsert true.

Parameters

document

the document to save

Throws

com.mongodb.MongoWriteException

if the write failed due some other failure specific to the update command

com.mongodb.MongoWriteConcernException

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

com.mongodb.MongoException

if the write failed due some other failure


suspend fun <T : Any> MongoCollection<T>.save(clientSession: ClientSession, document: T): UpdateResult?

Save the document. If the document has no id field, or if the document has a null id value, insert the document. Otherwise, call replaceOneById with upsert true.

Parameters

clientSession

the client session with which to associate this operation

document

the document to save

Throws

com.mongodb.MongoWriteException

if the write failed due some other failure specific to the update command

com.mongodb.MongoWriteConcernException

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

com.mongodb.MongoException

if the write failed due some other failure