I want to filter my data using filter specified as below:
var filter = { minAge: 2, maxAge: 11, country:'uk', city':'london'};
In which case the filtering will be:
r.db(dbName).table(tableName)
.filter(r.row("minAge").ge(filter.minAge)
.and(r.row("maxAge").le(filter.maxAge))
.and(r.row('country').eq(filter.country))
.and(r.row('city').eq(filter.city))
);
However some of the filter predicates could be missing for example if I have only min age and city, I want to filter only on them:
var filter2 = { minAge: 2, city':'london'};
Above filter should result in below
r.db(dbName).table(tableName)
.filter(r.row("minAge").ge(filter.minAge)
.and(r.row('city').eq(filter.city))
);
How to build a ReQL query according to my filter object keys that I could pass to the filter function.