Atomic counter updated by n1ql throws an error




When I update an atomic counter with n1ql, the document becomes unusual. It throws the following error when trying to increase via SDK. I used update query explained in How to update atomic counter with n1ql?

LCB_DELTA_BADVAL: The value requested to be incremented is not stored as a number

When I did exactly

  1. Updated an existing atomic counter with "update myBucket use keys "keyName" set myBucket=newNumber"
  2. Tried to increase the document in PHP SDK
    $bucket->counter('keyName', 1)


Is step 1 succeed.

The following seems to work fine.

insert into default values("k01",1);
update default use keys "k01" set default=10;
select * from default use keys "k01";
    "requestID": "0fd2c651-99b0-41d2-86ca-c7147dd2af62",
    "signature": {
        "*": "*"
    "results": [
            "default": 10
    "status": "success",
    "metrics": {
        "elapsedTime": "1.901646ms",
        "executionTime": "1.884669ms",
        "resultCount": 1,
        "resultSize": 37


Sorry for the delay in response. I will provide re-produceable code (or steps) later tonight


Sorry for the delay again. I’m trying to make sure I give you the exact information since I was a little confused as well. It did not work at work, but worked at home just fine.

Only difference is that I’m using 4.6.1-3652 Enterprise Edition at work, but 5.0 at home.

Steps to reproduce

insert into default values("k01",1);


$cluster = new CouchbaseCluster('couchbase://');
$bucket = $cluster->openBucket('default');
$bucket->counter('k01', 1);

Then this throws exception.

Update: I haven’t tested it with the latest SDK. I tested it with SDK 2.1.o


Is Exception from PHP SDK or query. Are you able to retrieve value using N1QL select. cc @avsej


I can select the doc using n1ql.

I get the exception from SDK.

I will try to come up with a docker that can reproduce it over the weekend if possible. I know this is confusing. It confused me a little as well.