You'll need guard clauses for the presence of the countries field, design documents get replicated too :)
You haven't specified what isn't working afaict. Can you clarify? B. On 30 March 2013 16:45, John <[email protected]> wrote: > Yes all docs (apart from the design docs) have the countries field, and it > always has atleast one entry. Would the fact expriyDate can sometimes be > set to null be an issue? Although the only working filter function I've > been able to create so far is with expiryDate. > > I tried your sample code and still can't get it to work, even with some > variations. I'm currently installing CouchDB on my desktop, as I'm assuming > then atleast I'll get access to the error logs, as iriscouch, which im > currently using doesn't provide them for free accounts > > > On 30 March 2013 15:27, Robert Newson <[email protected]> wrote: > >> 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" >>
