I have documents and a view where you can search by the keywords list. A document may look like:
{
_id: "foo",
keywords: ["bar", "baz"],
}
Then, I have the view:
map: function (doc) {
doc.keywords.forEach(function(word) {
emit(word, doc);
});
}
This works great in that I get the foo
document back, but the issue is if I don't provide a key I get this document twice which makes sense because it has two keywords. However, I only need/want the document once.
I have also added
reduce: function (key, value, rereduce) {
return value;
}
but this gives me reduce_overflow_error
. If I use return null
then the value I get for the document is null
which is no good either.
I've also read about using a list function for this, but I'm not sure where the list function is supposed to go in the couchapp. This also seems pretty complicated for what I think should be fairly simple.
How can I stop the duplicates from coming when querying the view?