Couchbase-返回不同的值 [英] Couchbase - return distinct values

查看:48
本文介绍了Couchbase-返回不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的小型JSON文档列表:

I have a list of small JSON documents in the format:

{
 "name":"Kate",
 "event":"read"
},
{
 "name":"Jon",
 "event":"delete"
},...

我的地图功能是这样:

function(doc, meta){
  emit(doc.event, null);
}

结果,我得到了所有事件的列表,包括重复事件.如何仅将结果集减少为不同的值?

As a result I get a list of all events, including duplicates. How do I reduce the resultset to distinct values only?

谢谢

推荐答案

这是另一个问题的答案,已修改为适合该问题.我希望这可以帮助别人!减少功能:

This is the answer from the other question, modified to suit this question. I hope this helps someone! The reduce function:

function(keys, values, rereduce) {
  return keys.filter(function (e, i, arr) {
    return arr.lastIndexOf(e) === i;
  });
}

这篇关于Couchbase-返回不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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