How to update atomic counter with n1ql?




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

Atomic counter updated by n1ql throws an error

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


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

Say I have the following atomic counter.


What do I use to update this?


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


Thanks @prasad

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


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.


Atomic Counter and Index

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.