Hello Guys I am wondering if there is a way to set the data consistency when I am performing an upsert using the nodeSdk and server 4.1
Are you talking about specifying the âdurability requirementsâ?
If so, you can do that with persist_to/replicate_to. See the node docs here: http://developer.couchbase.com/documentation/server/4.5/sdk/nodejs/document-operations.html
Hello Mathew,
I am talking about updating/mutating document concurrently. By using the CAS value to ensure that the update is a success.
I am not sure how to do this.
Thanks in advance.
@fernando_l thanks for the clarification. At that same link, âcasâ is listed as an optional parameter to upsert,insert,replace methods. I think maybe something like:
bucket.insert(âdocument_idâ, {âyourâ:âdocumentâ}, {cas: yourCase}, function(err, res) { });
You may also want to check out the SDK Bucket documentation here: Couchbase Node.js SDK Class: Bucket
Please let me know if I can help further!
yes just one question. How do I get the cas value? I guess I need to fetch the document doing a get and then grab the value from there.
When you retrieve a document (e.g. if you use the get
method), the callback method gets error
and result
.
From the docs here: http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.0/Bucket.html#OpCallback
âThe result contains at least a cas propertyâ
So if you have a result
object, then you can just use result.cas
.