insert

inline suspend fun <T> insert(collection: Collection, id: String, content: T, jsonSerializer: JsonSerializer? = null): TransactionGetResult

Inserts a new document into the specified Couchbase collection.

As with replace, the insert is staged until the transaction is committed. Due to technical limitations, it is not as possible to completely hide the staged data from the rest of the Couchbase platform, as an empty document must be created.

This staged data effectively locks the document from other transactional writes until the attempt completes (commits or rolls back).

Return

the document, updated with its new CAS value and ID, and converted to a TransactionGetResult

Parameters

collection

the Couchbase collection in which to insert the doc

id

the document's unique ID

content

the content to insert.

Throws

com.couchbase.client.core.error.DocumentExistsException

if the collection already contains a document with the given ID.