Why does curl http://localhost:5984/blog/_design/comments/_view/total_num?group=true
return
{"rows":[
{"key":"sum","value":23},
]}
and not
{"rows":[
{"sum": 23},
]}
Why does curl http://localhost:5984/blog/_design/comments/_view/total_num?group=true
return
{"rows":[
{"key":"sum","value":23},
]}
and not
{"rows":[
{"sum": 23},
]}
Each row can have additional data, such as document data (doc
) for include_docs=true
queries.
In addition to Alex and Tim's responses:
There are a couple different reasons.
As Tim McNamara points out, having the key as the member name in the result row means that keys are limited to strings because of the rules of JSON. This way allows people to have view keys of any JSON type.
As Alex Koshelev points out, if we allowed keys as object member names in the view row then the key and value would not be directly addressable. This means that you would have to investigate each and every row to figure out what the key was.
A second aspect of the namespace issue is that a key could conflict with any metadata that may be included in that row. For instance with include_docs=true or the included docid member for non-reduced view output.
Alternatively, if you would like to reformat the output to suit your needs, you can use a _list function to change each row to your liking.