Update document using N1QL with CAS value

n1ql
#1

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?

N1QL update with CAS
#2

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

#3

@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.

#4

Hi @bentonam,

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

#5

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.