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

save

fun <T : Any> MongoCollection<T>.save(document: T): Unit (source)

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

Exceptions

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

fun <T : Any> MongoCollection<T>.save(clientSession: ClientSession, document: T): Unit (source)

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

Exceptions

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