Couchbase - return distinct values

二次信任 提交于 2019-12-12 15:24:16

问题


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

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

My map function is this:

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?

Thank you


回答1:


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


来源:https://stackoverflow.com/questions/20348525/couchbase-return-distinct-values

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