In Couchbase Server 3.0, the documents in my bucket are of the form:
{ "id":"xyz", "categories":["news", "articles", "etc.etc.."]}
I want to write a view such that when I specify key="news", all the documents that include "news" in the "categories" array attribute will be returned.
I went as far as writing a map function that emits the same article as many times as we have elements in "categories" array.
function (doc, meta) {
for(var i = 0; i < doc.categories.length ; i++)
emit(doc.categories[i], doc);
}
But I'm stuck with the reduce.
Turns out the map function is sufficient, I just needed to query with key="cateogoryName" in the URL.
I was initially confused because if you don't wrap the key in quotes in the query you get a very mysterious error, see: https://issues.couchbase.com/browse/MB-7555
Not sure if a reduce function would be more efficient though..