2

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; 
}
user4893295
  • 533
  • 6
  • 25

2 Answers2

2

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.

Alexis Côté
  • 3,670
  • 2
  • 14
  • 30
  • Ah I see that, that works. Can I make the reduce permanent? I'm using Nano in NodeJS and I can't find any way of specifying the reduce flag. – user4893295 Jul 18 '17 at 17:09
  • Simply pass the following flag in the param object : {reduce: true} – Alexis Côté Jul 18 '17 at 18:16
  • If I specify this, it totals all the tags and just gives me a key of 'null' and a value of the total number of tags, whereas displaying it in Fauxton correctly groups it by the tagname as key?... – user4893295 Jul 19 '17 at 11:04
  • This is going off topic. Perhaps create another question for this new problem? – Alexis Côté Jul 19 '17 at 12:39
  • 1
    I can't find this Options button and there's no Reduce option in Fauxton. Maybe they changed the interface? I have the same problem as OP. When my views are saved, only the map function is applied. I can't find a way to apply the reduce functions to my views. – John Smith Optional Jun 28 '19 at 00:01
  • @JohnSmithOptional I answer your question on another response. https://stackoverflow.com/a/62060926/6595016 – Marco May 28 '20 at 09:06
0

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

Marco
  • 1,073
  • 9
  • 22