Using reduce with a composite key in couchdb view returns no result on GET -
i have couchdb view following map function:
function(doc) { if (doc.date_of_operation) { date_triple = doc.date_of_operation.split("/"); d = new date(date_triple[2], date_triple[1]-1, date_triple[0], 0, 0, 0, 0) emit([d, doc.name], 1); } }
when issue request this, whole view's data (2.8mb):
$ curl -x http://somehost:5984/ops-db/_design/ops-views/_view/counts % total % received % xferd average speed time time time current dload upload total spent left speed 100 2751k 0 2751k 0 0 67456 0 --:--:-- 0:00:41 --:--:-- 739k
however, when add reduce function:
function (key, values, rereduce) { return sum(values); }
i no longer data when using curl:
$ curl -x http://somehost:5984/ops-db/_design/ops-views/_view/counts % total % received % xferd average speed time time time current dload upload total spent left speed 100 42 0 42 0 0 7069 0 --:--:-- --:--:-- --:--:-- 8400
the result looks this:
{"rows":[ {"key":null,"value":27065} ]}
this view & map & reduce functions added using futon interface , when reduce checkbox checked there, 1 row every 'date, name' pairs values accumulated pair. changes when queried through get?
when calling view through curl can try passing in necessary parameters triggering reduce , grouping
e.g.
explicitly tell couchdb run reduce
function
$ curl -x http://somehost:5984/ops-db/_design/ops-views/_view/counts?reduce=true
or group
, group_level
params
you can read more on available options here (under querying options
section)
Comments
Post a Comment