Unable to make upsert/replace fail with wrong cas


#1

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?

Thanks!


#2

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


#3

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?


#4

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)


#5

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


#6

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

Will then have to wait till it is implemented.


#7

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