Without knowing more about your data set, It’s difficult to know what the problem is. Base don the map reduce:
function (doc, meta) {
if (doc.doc_type == “user_doc” && doc.status) {
if (doc.role == “Administrator”) {
emit(doc.role, {“id”: doc.id, “display_name”: doc.display_name, “email”: doc.email});
} else if (doc.role == “ContentAuthor”) {
emit(doc.role, {“id”: doc.id, “display_name”: doc.display_name, “url”: doc.url, “email”: doc.email});
} else if (doc.role == “ContentPublisher”) {
emit(doc.role, {
“id”: doc.id,
“company_name”: doc.company_name,
“display_name”: doc.display_name,
“url”: doc.url,
“email”: doc.email
});
}
}
}, reduce:"_count"
I suspect there’s something causing duplicate counts within the documents, or there’s a consistency window issue where a document is being added/deleted/changed before the view has updated.
As an alternative, you can try achieving similar functionality using _sum to aggregate by doc.role:
map:function (doc, meta) {
if (doc.doc_type == “user_doc” && doc.status) {
emit(doc.role,1)
}
},reduce:"_sum"
Thanks
Todd Greenstein