How to replace couchbase document with CAS - couchbase node js 2.0
I have a CAS ID that I got from a document request with the get () method. Now I want to update the same document only if its CAS value has not changed.
So for this I need to provide the CAS in the replace () method, but I don't know how.
Please help me if anyone knows how to do this.
Thank.
+3
source to share
1 answer
Using the API docs at http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.0/Bucket.html#replace you can do it like this:
var myCas = ...;
var myBucket = myCluster.openBucket();
myBucket.replace('document_name', {some: 'value'}, {cas: myCas},
function(err, res) {
if (err) {
console.log('operation failed', err);
return;
}
console.log('success!', res);
});
+4
source to share