According to the Scala SDK documentation (Sub-Document Operations | Couchbase Docs). Here is the quote from your documentation
When submitting multiple mutation operations within a single mutateIn command, those operations are considered to be part of a single transaction: if any of the mutation operations fail, the server will logically roll-back any other mutation operations performed within the mutateIn, even if those commands would have been successful had another command not failed.
What I understand is that all subdocument operations within a single mutateIn are either all succeeded or all failed.
With that in mind. Lets consider below is the document we want to do sub document operations on.
{
"subList1": ["a", "b"],
"subList3": ["c", "d"]
}
What we want is to upsert sub documents whose keys are “subList1” and “subList2” and to remove sub documents with keys “subList3” and “subList4” (since “subList4” is not exists our operation will fail).
Here is the sample code in scala (I didnt include the entire codebase for brevity):
val mutateInSpecs: Seq[MutateInSpec] = Seq(
MutateInSpec.upsert("subList1", Seq("y", "z"))(Codec.codec[Seq[String]]),
MutateInSpec.upsert("subList2", Seq("k", "l"))(Codec.codec[Seq[String]]),
MutateInSpec.remove("subList3"),
MutateInSpec.remove("subList4"),
)
// perform mutateIn
aCollection.async.mutateIn(DOCUMENT_KEY, mutateInSpecs, MutateInOptions(expiry = Duration.apply(expiry, TimeUnit.SECONDS)))
Since the above operation fails, I expected that the document will not be changed. However the document became like this:
{
"subList1": ["y", "z"],
"subList2": ["k", "l"],
"subList3": ["c", "d"]
}
Although stated in docs, operations are not executed atomically. Upsert operations applied but remove operations are not. Is there a way to control this behavior?
CB server version: Enterprise Edition 7.0.3 build 7031
Scala SDK version: Tried both 1.1.6 and 1.0.7