How to provide a CAS to Node SDK subdocument mutation command

I have code like this:

cas = getCASforDoc(key)
bucket.mutateIn(key)
                .upsert(path, value)
                 .execute()

I want to mutate the document so long as the document hasn’t been mutated since I retrieved the CAS.

The node.js sdk hints that it’s possible but I can find how.

ok, I haven’t tested out, but https://stackoverflow.com/questions/57252109/how-to-get-cas-value-while-performing-an-update-using-couchbase-subdocument-api

suggests I do

bucket.mutateIn(key)
               .withCas(cas)
               .upsert(path, value)
                .execute()

Hey @naftali,

Try this!

bucket.mutateIn(key, {cas: cas})
    .upsert(path, value)
    .execute(...);

Cheers, Brett

1 Like