The data in couch has a record for each contact type as follows.
[{
"_id":"1"
"contact_type":"AA"
"contact_email" : "userA@domain.com"
},{
"_id":"2"
"contact_type":"BB"
"contact_email" : "userA@domain.com"
},{
"_id":"3"
"contact_type":"CC"
"contact_email" : "userA@domain.com"
},{
"_id":"4"
"contact_type":"AA"
"contact_email" : "userB@domain.com"
},
{
"_id":"5"
"contact_type":"BB"
"contact_email" : "userB@domain.com"
}]
Records 1,2,3 represent contact with the email userA@domain.com while records 4 and 5 represent contact with an email userB@domain.com.
My task is to build a query to get the total amount of unique contacts (2 in this case) but I am not sure how this can be achieved.
Currently, I have a map function with _count reduce
function(doc){
emit(doc.emailAddress, 1);
}
which returns
{
"rows":
{
"key" : "userA@domain.com",
"value" : 3
},
{
"key" : "userA@domain.com",
"value" : 2
}
}
However, what I need is the total amount of those records above, i.e. something like
{
"total" : 2
}
(Note: the database is large so looping through the mapped/reduced view to count the records is not an option)