Bucket.counter, autoincrementing keys

Using couchbase version 4.6.

How to instruct to increment the key automatically by increments of 1?

Documentation search shows to use bucket.counter method. But ‘Counter’ is not recognized as a property/method

@rkbnair -

The .NET SDK has the Increment function, so something like:

 var result = bucket.Increment("thecounterkey");
        //do something with result

That will create a key if it doesn’t exist and increment it by one; if the key exists, it will increment the key by 1.


No, it didn’t help. It just created a key with name 'thecounterkey"

@rkbnair -

Odd, the value of ‘thecounterkey’ should be 1. Which client version are you using?



First insert, it works. However, subsequent inserts, it updates instead. Should be creating 1,2 3 etc.

var result = _bucket.Increment(“1”);
//if (result.Success)
var doc = new Document
//Id = model.Key,
Id = Convert.ToString(objData.ID),
Content = tmpProfile
//Content = model.Value

Sorry, my mistake.

It works !