如何在Fauxton中使用reduce [英] How to use reduce in Fauxton

查看:74
本文介绍了如何在Fauxton中使用reduce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在接受一些Couch培训,但无法弄清楚如何在Fauxton中使用reduce。选择地图区域下方的 _count本身不会执行任何操作。我尝试将其添加到地图代码下方,但是我想我需要以某种方式对其进行集成。在我的示例中,我试图计算每个标签在所有文档中的使用次数。这是我的查看代码:

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


推荐答案

您将地图函数放在地图区域。然后,选择缩减功能(可以是自定义或本地缩减功能)。

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

然后,从设计文档中选择视图。点击选项,然后选择减少选项。然后,运行查询,并应用您的reduce函数。

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.

这篇关于如何在Fauxton中使用reduce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆