CAS de/serialization not possible

Using a de-serialized/ serialized CAS value of a couchbase document for a set operation produces an error in couchnode. The Error is { [Error: Bad CAS] code: 4098, at: { ‘0’: 84213760, ‘1’: 193011187 } }.

The following code snippet reproduces the error:

couchbase = require('couchbase'); db = new couchbase.Connection({bucket: "default"}); db.get("foo", function(err, result) { db.set("foo", result.value, {cas: JSON.parse(JSON.stringify(result.cas))}, function(err, result) { console.log(err, result); }); });

We need serialization, because we want to pass the CAS value to the clients browser.

A workaround is to take a “native” cas value from an arbitrary document and override this CAS Object with the javascript properties of the de/serialized cas object of the document. A set operation with this overridden native CAS object is working as expected. it fails if the cas value differs and succeed if the cas value is the same.

It seems to be a bug in couchnode, can you verify these?

our stack is:
node v0.10.29
couchnode (npm couchbase) version 1.2.1
couchbase 2.2.0

Hello @pithu,

As I see it is supported now, however not with JSON.stringify/parse but instead with simple .toString(). Check the unit test of the changeset here:

Just use cas.toString() to serialize and use the given raw string as the value in the options.cas property.

Hope this helps,

  • György