I want to make search function that search all document containing specific tags using couchdb view.
Assume I have the following documents:
{
"_id": "1",
"tags": ["abc", "acb", "abd"]
}
{
"_id": "2",
"tags": ["abc", "acb"]
}
And my map function:
function(doc) {
for(var idx in doc.tags)
emit(doc.tags[idx], doc._id)
}
when I want to find all documents which contains tags started with ab
, i can use query parameter ?startkey="ab"&endkey="ab\u0999"
, and couchdb returned
{"total_rows":5,"offset":0,"rows":[
{"id":"1","key":"abc","value":"1"},
{"id":"2","key":"abc","value":"2"},
{"id":"1","key":"abd","value":"1"}
]}
How to make reduce function, so couchdb will return unique id from my view?