Update document using N1QL with CAS value

Example Query to retrieve a user document and CAS value.

SELECT u.*, META().cas FROM users AS u USE KEYS 'user_1234'

How do you update a document using the CAS value?

Can you be more specific? You cannot update the CAS value using N1QL.

@geraldss lets say that the document had been retrieved through the SDK using getAndLock for example, the only way to update that document would be to set the CAS value at the time of the update.

What I am trying to determine is, if it is possible through N1QL to specify the CAS value to use when attempting to do an UPDATE through N1QL. For example

UPDATE users USE KEYS 'user_1234' SET email = 'something@domain.com' WHERE META().cas = 1464107842363301760

However this does not work.

Hi @bentonam,

For now, you cannot perform the update using N1QL, if you need to supply a matching CAS value.

Note that if you happen to be using 4.5 beta and a capable SDK, one option available to you is the new subdocument operations. There is a mutateIn() which would allow you have the optimistic concurrency of CAS along with mutating only the email attribute of the document. There is a blog that introduces the feature.