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.
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.
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?
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/.
@brett19
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> }
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.
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.