Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couchbase - return distinct values

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

like image 514
Katya S Avatar asked Feb 17 '26 00:02

Katya S


1 Answers

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;
  });
}
like image 72
Katya S Avatar answered Feb 20 '26 20:02

Katya S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!