Unable to make upsert/replace fail with wrong cas

Try now to make upsert or replace fail for 2 h and I am totally unable. It seems like the cas value gets totally ignored. No matter what I set it to it works. No error or anything it simply updates the document.

So this one works for example totally fine:

myBucket.replace(id, data, {"cas": {"aaa":"aaa"}}, function(err, result) {

Anyobody experiences something similar?


Hey janober,

CAS values are indeed checked, but only in the case that the CAS value you have passed is a valid CAS object returned by one of the other methods. This is because Node.js does not internally support the data type used for a CAS, and thus we must wrap it.

P.S. This does apparently exhibit a bug where bad CAS values are not triggering an error, I’ve created a ticket to track this here: https://issues.couchbase.com/browse/JSCBC-195.

Cheers, Brett

Thanks for the fast answer and for confirming the bug.

Wonder then about one other thing. When I use “get()” I guess everything should be fine. I get my cas-object with the numbers that I can pass back. But what when I use N1QL and “query()”? I saw that I can get apparently the cas when query something like that: “meta(mybucet”).cas"

That means then that if I use get I have this: (which will probably work fine)

   { cas: 
      { '0': 2651848704,
        '1': 1399048988 } 

And if I use N1QL I get this: 18271273968467 ?!?!

What do I do with that value? How can I use it as cas for upsert/replace?

Probably better if I create a new one for the above. So I did:
2848 (somehow I am not allowed to post the link simply the number)

Hey Janober,

We do not currently have a solution to this problem, but I hope to solve this for our next release.
See here for ticket: https://issues.couchbase.com/browse/JSCBC-196.

Cheers, Brett

Thanks a lot for your help! Seems I am quite unlucky… :wink:

Will then have to wait till it is implemented.

Hey Guys,

Just wanted to let you know that that ticket is now resolved for the latest code available in Git (it will be published in a release on March 3rd). You can now pass string-encoded numbers as a CAS, allowing you to use N1QL values which are returned. Additionally we now support serializing and inspecting the state of CAS values. See here for the changeset: http://review.couchbase.org/#/c/46609/.

Cheers, Brett

Did the cas handling change with sdk 3.0?
Before I was just passing the cas variable as it was passed to be by the previous operation, but now I always get the error “a bad cas was passed”.
Here is a sample of what I get : CbCas { ‘0’: <Buffer 00 00 9c e8 68 aa 19 16> }

Hey 00christian00,

I think there was a change in some underlying code which made it illegal to pass a CAS value to the upsert operation. This is likely the cause of the issue you are seeing. If you have a CAS, try using it with a replace operation instead and I imagine it will succeed.

Note that an Upsert operation with a CAS is a bit odd, as its essentially going to have identical behaviour to a Replace.

Cheers, Brett

Thanks @brett19 . I was using upsert since I have some high level layer above couchbase and was using one of the existing method for simplicity.
It works now thanks.

Update parallet document with upsert

Error: bad cas passed

const data = col.query(‘SELECT data, meta().cas FROM test WHERE meta().id = “123”’)
col.upsert(‘123’, {data: }, {cas: data.rows[0].cas})