How to update atomic counter with n1ql?

n1ql

#1

Hello,

Is there a way to update an atomic counter with n1ql?


Atomic counter updated by n1ql throws an error
#2

You can use the UPDATE statement, which atomically updates a document/field. Provide more details/example, if you are referring to something else.


#3

Unlike other documents, atomic counter does not have a field.

Say I have the following atomic counter.

3333

What do I use to update this?


#4

Try this:
INESRT INTO bucketName values (“atomic”, 5);
SELECT meta().id, * from bucketName USE KEYS “atomic”;
UPDATE bucketName USE KEYS “atomic” SET bucketName = 6;


#5

Thanks @prasad

That syntax is very weird…but it worked :slight_smile:


#6

Hi Moono326,
Note that the value here is a scalar/basic type, unlike a typical JSON object with key/value pairs. Hence the syntax. It will help if you can clarify why you feel it is weird, or any suggestion to make it better.

thanks.
-Prasad


Atomic Counter and Index
#7

I guess it’s just new to me.

It almost felt like updating the bucket itself.

Nothing wrong, it just felt somewhat new.

Thank you for the help.