couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luca Morandini <>
Subject Re: Is it possible to really "reduce" the output of a reduce?
Date Fri, 27 Mar 2015 13:03:58 GMT
On 26/03/15 07:11, Russell McOrmond wrote:
>    For most of the hundreds of thousands of keys, the reduce function has
> nothing to return -- and I'd like to quickly skip over them and get to the
> few keys where I did have something to return.

You should define a way to aggregate the documents produced by the map function at 
an higher level, since at the un-grouped level there must be one result per document.

For instance, this reduce function does return empty arrays when the name 
attribute does not contain "fer" and the level is un-grouped, but drops the empty 
arrays when grouping, reducing the output significantly (OK, depending on the data 
you've got):

function (keys, values, rereduce) {
  var result= [];
  if (rereduce === false) {
    values.forEach(function(v) {
      if ("fer") !== -1) {
  } else {
    values.forEach(function(v) {
      if (v.length > 0) {
        result= result.concat(v);
  return result;

Hope this helps.


Luca Morandini
Data Architect - AURIN project
Melbourne eResearch Group
Department of Computing and Information Systems
University of Melbourne
Tel. +61 03 903 58 380
Skype: lmorandini

View raw message