Uploaded image for project: 'Couchbase Java Client'
  1. Couchbase Java Client
  2. JCBC-1156

add API doc on how to override a counter

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Minor
    • 2.7.3
    • None
    • Documentation
    • None

    Description

      Use case is to effectively set a counter to a given value, even though it already exists.  It seems the canonical, modern way to do this is as follows:

      bucket.remove("countme");
      bucket.counter("countme", 1, 0); // init at 0, incr by 1 if exists
      System.out.println(bucket.counter("countme", 1).content()); // prints 1
      JsonLongDocument overrider = JsonLongDocument.create("countme", new Long(99));
      bucket.upsert(overrider);
      System.out.println("after increment: " + bucket.counter("countme", 1).content()); // prints 100

      But the API reference discussion of counters doesn't currently make that clear.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              subhashni Subhashni Balakrishnan (Inactive)
              ingenthr Matt Ingenthron
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty