Details
-
Bug
-
Resolution: Fixed
-
Major
-
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
- relates to
-
MB-6961 result of INCR operations should show up in views as JSON number, not base64 string
- Closed