I have a table called 'conditions' which contains JSON documents structured as such:
{
"keyA": "valueA",
"keyB": "valueB",
"symptoms": ["foobar", "bar", "cough", "itch"]
}
I simply would like to execute a query which returns all documents that have symptoms which match a regex.
The closest I have gotten is with this query:
r.db('database_name').table('conditions').filter(r.row('symptoms').nth(0).match('oob'));
This would return the document (row) since it matches with the 0th element "foobar".
However I'm simply unable to figure out a way to iterate over the whole array. E.g. if "foobar" were to be the last element in the "symptoms" array it wouldn't match.
Any help would be appreciated, Thanks
Edit: I figured it out by myself. Heres the query that works:
r.db('database_name').table('conditions').filter(function(row){
return row('symptoms').contains(function(symptom){
return symptom.match('foo')
})
})