How to use reduce in Fauxton

717 Views Asked by At

I've been following some Couch training, but cannot figure out how to use reduce in Fauxton. Selecting '_count' underneath the map area does nothing by itself. I have tried adding it below the map code, but I guess I need to integrate it somehow. In my example I'm trying to count how many times each tag is used in all documents. This is my view code:

function (doc, meta) {
  if(doc.tags) {
    for(var i in doc.tags) {
      emit(doc.tags[i],1);
    }
  }
}

function (tag, counts) {
  var sum = 0; for ( var i = 0; i < counts.length; i++) { 
    sum += counts[i]; 
  }; 
  return sum; 
}
2

There are 2 best solutions below

6
On BEST ANSWER

You put your map function in the map area. Then, you select your reduce function (it can be custom or native reduce functions).

Then, select your view from the design documents. Click Options and select the Reduce option. Then, run the query and your reduce function should be applied.

0
On

I had trouble finding how to display the result of the reduce function, not only the map function.

  • You need to run the map query.
    1. Then click on the option at the top right corner of your screen.
    1. Select "Reduce".
    1. Finally click on the "Run query" button.

Description of part 1 and 2