Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-15129

view engine treats counters as binary.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 4.0.0
    • 3.0.3, 4.0.0
    • Security Level: Public
    • None
    • Mar 9 - Mar 27

    Description

      When a counter is created it is created as a binary object and not a JSON document. As a result it makes it hard to use in a view.

      For example create a counter:

      cbc-incr counter_101 --initial 22 --delta 1
      

      Create a view:

      function (doc, meta) {
        if (meta.id.indexOf("counter_") === 0) {
          emit(meta.id, doc);
        }
      }
      

      Query the view, you see the value is base64:

      {"total_rows":1,"rows":[
      {"id":"counter_1","key":"counter_1","value":"MjI="}
      ]
      }
      

      As a work around you can use following view:

      function (doc, meta) {
        if (meta.id.indexOf("counter_") === 0) {
          var decode = decodeBase64(doc);
          var value = null;
          for (i = 0; i < decode.length; ++i) {
            if (value == null) {
              value = String.fromCharCode(decode[i]);
            } else {
              value += String.fromCharCode(decode[i]);
            }
          }
          emit(meta.id, parseInt(value));
        }
      }
      

      Query the view and you can the value is an integer:

      {"total_rows":1,"rows":[
      {"id":"counter_1","key":"counter_1","value":22}
      ]
      }
      

      It would be useful if the view engine could detect if it is a counter and convert or have a helper function like dateToArray and decodeBase64 that the developer could call.

      Attachments

        Issue Links

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

          Activity

            People

              abhinav Abhi Dangeti
              pvarley Patrick Varley (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty