Reputation: 2113
I have data in taffy DB that look like this. Data points can be blank:
{"first_name":"Sam", "last_name": "Andrew", "age":26 ... }
{"first_name":"Jane", "last_name": "Doe", "age": 19 ... }
{"first_name":"John", "last_name": "Deer", "age":51 ... }
.
.
.
If i need all the rows where the first name is either "John" or "Jane", the age is between 40 and 60, the query would be:
{
"name":["John","Jane"],
"age":{"lte":60,"gte":40}
}
Now if I add the condition that the age can be less than 20 as well, I am unable to write a query for that.
I have tried this but it does not work:
{
"name":["John","Jane"],
"age":[{"lte":60,"gte":40},{"lte":20}]
}
Any help would be greatly appreciated.
Upvotes: 0
Views: 262
Reputation: 191
It helps to break this down into an age-related or
statement and the Name-and-Age and
statement.
You want the Name condition and the Age condition (which contains its own or
)
A standard and
statement is normally written (in pseudocode) as:
db({name_condition, age_condition})
but can also be written as
db({name_condition},{age_condition})
This second notation is needed to accomplish the compound condition you're looking for.
Because your entire Age condition is effectively one simple or
statement, you'd put it in an array.
[
{age:{"lte":20}},
{age:{"gte":40,"lte":60}}
]
Either age is less than than 20 or age is between 40 and 60.
The Name condition is straightforward
{first_name:["John","Jane"]}
Put the two objects together into an and
statement like this:
db({first_name:["John","Jane"]},[{age:{"lte":20}},{age:{"gte":40,"lte":60}}])
Upvotes: 3