How to update atomic counter with n1ql?

Hello,

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

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.

3333

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.

thanks.
-Prasad

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.