How to use reduce in Fauxton

久未见 提交于 2019-12-13 00:33:38

问题


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; 
}

回答1:


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.



来源:https://stackoverflow.com/questions/45169466/how-to-use-reduce-in-fauxton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!