Reputation: 44371
As specified here, a filter can be used with the _changes feed like this:
curl "$HOST/db/_changes?filter=app/important"
Now I am trying to use this pattern with a standard view access, like this:
curl -X GET $HOST/db/_design/live_data/_view/all-comments&filter=live_data/bytag?tag=testing
I have also tried ? instead of &:
curl -X GET $HOST/db/_design/live_data/_view/all-comments?filter=live_data/bytag?tag=testing
But the filter has no effect: all documents are shown, even those which should not be validated by the filter.
The filter that I am using is:
function(doc, req)
{
for( var i in doc.tags ) {
if(doc.tags[i] == req.query.tag) {
return true;
}
}
return false;
}
_changes
feed? I have seen no examples of filters except related to _changes
Upvotes: 2
Views: 658
Reputation: 12159
If this worked it would impose on CouchDB the responsibility of iterating through all the view's records and execute the filter function on them. It is not a good way of doing things, especially when you have the possibility of pre-indexing documents using views and arrays of keys (like [date, tag]
).
But nothing will forbid you of implementing this filter in a backend of your own. You would only have to load all the view documents from CouchDB, execute the filter function on them and return. But that wouldn't be fast.
Upvotes: 1
Reputation: 269
Yes, it seems that filters are limited to _changes requests only. If you want to filter data from views, you can use "startkey" and "endkey" parameters with possibly more complex json keys and/or reduce grouping levels to achieve your desired results.
Upvotes: 1