Subdocument Upsert with 3.x client missing

In the 2.x client, we were able to:

BUCKET.mutateIn(keyProvider.getCouchbaseKey(key))
                .upsertDocument(true)
                .withExpiry(ttl)
                .withCas(cas);

However, with the new version of the client and MutateInOptions there appears to be no upsertDocument() capability. How can we perform this same operation?

Thanks - H

1 Like

Hi @unhuman
In SDK3 you instead can do a MutateInSpec.replace(“”, YOUR_CONTENT). The “” indicates the root of the document.

1 Like

In SDK 3 you’d use MutateInOptions.storeSemantics( StoreSemantics.UPSERT )

1 Like

I think your solution would replace the entire document if it existed, which doesn’t necessarily mesh up with only updating certain paths… I think the StoreSemantics provided by @david.nault is a better solution (and works with my existing tests, as a bonus)

@unhuman yes, I think I misread your question - David’s answer is the correct one here.

1 Like