3

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

Katya S
  • 1,321
  • 3
  • 17
  • 31

1 Answers1

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;
  });
}
Katya S
  • 1,321
  • 3
  • 17
  • 31
  • 1
    if you do this you could encounter an error solved here: http://stackoverflow.com/questions/31152576/error-reducer-when-attempting-to-do-distinct-reduce – Avlin Dec 15 '15 at 21:12