incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Wex" <>
Subject Basic re-understanding of reduce.
Date Wed, 24 Dec 2008 01:53:51 GMT
I have been working on a few projects with couchdb, some of which are
in production so it came as a complete surprise today when I realized
I don't understand CouchDB's reduce implementation.

I have a map that emits a complex key and a count of 1 for each
document. From that I end up with a data set like so:


Now what I want from my reduce if the above was the only output is to
end up with a set like so:


I thought my reduce statement would have to look simply like so:

function(keys, values) {
  return sum(values);

Much to my surprise, when I didn't get the numbers expected, I did
some logging from my reduce function:

  "keys": [
    [[341263,"teasered","127"],"ae447f40-51cd-406e-8a65-f5a7f163d20e"], ...
 "values": [1,1,...],
 "rereduce": false

I thought that the reduce function was only called with results of the
same key. Essenially I think I was assuming that the functionality of
reduce when rereduce is true was always the case. Can someone help me
understand why a reduce function would get multiple keys for a single
reduce? Also, what should my reduce then look like?

Thanks for the help, Simon.

View raw message