do *all* docs have a "countries" field? You'll be throw exceptions for
docs that don't. Also, a filter function is expecting true/false
responses. Something more like;
function(doc, req) {
if (!doc.expiryDate) return false;
if (!doc.countries) return false;
if (!req.query.today) return false;
if (!req.query.country) return false;
return doc.expiryDate > req.query.today &&
doc.countries.indexOf(req.query.country) !== -1;
}
On 30 March 2013 14:44, John <[email protected]> wrote:
> How does CouchDB handle JSON arrays? I'm trying to create a filter for
> selective replication and I've tried everything to try and iterate through
> the contents of an json array to check the contents but nothing seems to
> work. My code is:
>
> function (doc, rec) {
> if (doc.expiryDate == null && doc.countries.indexOf(rec.query.country) !=
> -1) {
> return doc;
> } else {
> var expiry = doc.expiryDate;
> if (expiry > rec.query.today
> && doc.countries.indexOf(rec.query.country) != -1) {
> return doc;
> }
> }}
>
> And the JSON looks like:
>
>
> "countries": [
> "GB",
> "US"],
>
> I've ran out of ideas of how to get this working now, although I'm sure the
> problem is "doc.countries"