I am using nodejs's nano npm module and couchdb to get the total number of documents based on a status message that I should be able to pass in a couchdb view.
The view looks like the following.
{
_id: "_design/docCount",
views: {
fileCountByStatus: {
reduce: "_count",
map:
'function (doc) {\n if(doc.status === "COMPLETE") {\n emit(doc._id, 1);\n }\n}'
},
},
language: "javascript"
}
I am accessing the above view using nano's view function.
My question is, is there anyway I can pass the doc status using the view function instead of hardcoding it (COMPLETE in the above case)
Answering my own question.
The general case is to create an index on status with a map function like this:
Then you can query the view for any value of status