function (doc, meta) {
emit(doc.account, [doc.phone, doc.email]);
}
So now how can I count how many phones and emails for this key. Note I do not want to create list of phones per document. Bassicaly each request in my system creates a new entry and then I want to check if someone who is using this account has for instance tried entering a different phone number or email… So in most request the phone count and email count should be always 1 but if it’s higher then 1 then I know it’s problem. This is basically for fraud analytics.
Well the way the reduce works is, it aggregates the count of the unique keys.
For example, the emit function is always of the form emit (key, value)
In your example, you had only 1 key that got emitted 4 times, so the count is 4.
If you want to do unique combinations, you could use an array and then the group_level.
emit ([doc.a, doc.b], doc.value)
In this case, _count will count all unique doc.a’s for group level 1. or count all unique combinations of [doc.a,doc.b] values if you use group level 2.
hope this helps explain how grouping and the reduces work. If the value portion is a number, you can use _sum and _stats.