On Mon, Sep 28, 2009 at 10:31 AM, Adam Wolff wrote: > If you change your map like this:       var value ={}; >       value[domain] = 1; >       emit([key...], value); > > Then you don't need conditional handling of rereduce. You can just write: >           values.forEach(function(v) { >               for (var k in v) { >                   hist[k] = (hist[k] || 0) + v[k]; >                } >            } > Just a warning that keeping a growing dictionary in your reduce values can be considered an anti-pattern. You'll get reduce overflows on big data sets. > A > > On Mon, Sep 28, 2009 at 9:31 AM, Jesse Hallett wrote: > >> It is entirely possible to do what you want.  The reduce function required >> is reasonably complicated. >> >> First I want to point out that in the example query you gave the results >> will not be filtered by engine.  If you want results matching only a >> specific category_id and engine you will have to move `engine` to the >> second >> or first position of the key.  If you want to get all engine values for a >> given date range then the last position in the key is appropriate. >> Otherwise the map function is looking good. >> >> Here is a reduce function that should work: >> >>    function (keys, values, rereduce) { >>        var hist = {}; >>        if (rereduce) { >>            values.forEach(function(v) { >>                // v is the intermediate output of a previous reduce call. >>                for (var k in v) { >>                    hist[k] = (hist[k] || 0) + v[k]; >>                 } >>            } >>        } else { >>            // v is a domain. >>            values.forEach(function(v) { >>                hist[v] = (hist[v] || 0) + 1; >>            } >>        } >>        return hist; >>    } >> >> Make sure to run your queries with `group=true`.  Futon uses `group=false` >> in the interactive view editor - so results may not look correct there. >> >> The 'Introduction to Views' wiki page is very helpful to me for getting a >> good idea of how reduce functions work: >> >>    http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views >> >> On Sep 28, 2009 7:21 AM, "Jeremy Wall" wrote: >> >> Typing from my phone so I can't give a code example. But from what you are >> describing I think you want a key that looks something like this. >> [CategoryId, Date, domain]. You can then use reduce to return counts by >> category, date, and domain. If you want counts that span categories and >> dates though then you will have to merge them in your application code. >> >> Sent from my G1 google phone >> >> On Sep 28, 2009 12:42 AM, "Glenn Rempe" wrote: Hello, I >> am >> hoping the group can ... >> > -- Chris Anderson http://jchrisa.net http://couch.io