I'm using javascript in CouchDb to build a filter which takes arguments. In the filter I'm trying to retrieve an array in CouchDB and see if it contains a parameter I pass in. I know the data going in is fine, and the function works fine without this code: `(countries.indexOf(rec.query.country) != -1)` I can't figure out what's going on. The complete function looks like:

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;

JSON for countries inside the document looks like:

"countries": [

The query:


Any ideas? I'm convinced `doc.countries` is the problem but have no idea how to successfully iterate on it and check its contents?