Overview
Many API detail
and aggregate
queries take a filter parameter which allows the developer to pair down records which are returned or included in the aggregates.
The filter parameter uses JSON
to express logical queries. The logical operators and nesting combine simplicity with power.
Simple Equality Queries:
In the following query, AgentId
must be 7321. Multiple field/values can be expressed in the same filter.
{
"AgentId": 7321,
}
This would be the equivalent of the longer form:
{
"AgentId": { "$eq": 7321}
}
Logical Operators
Fitlers can take any of the following logical operators:
- $eq - Equal to
- $ne - Not equal to
- $gt - Greater than
- $gte - Greater than or equal to
- $lt - Less than
- $lte - Less than or equal to
- $in - Takes an array input, true if the field is one of the items in the array
- $nin - Takes an array input, true if the field is not one of the items in the array
$in and $nin
The $in
and $nin
operators take an array of values:
{
"AgentId": { "$in": [2718, 2719, 2720, 2721]}
}
Logical conjunctions
The logical conjunctions take one or more subqueries and combine and nest them allowing the caller to narrow the search results to just the records they are looking for.
- $and - all sub expressions must be true
- $or - At least one of the sub expressions must be true
- $not - the sub expression must not be true.
Example: $and
{
"$and": [
{"QueueId": 1221},
{"AgentId": 2232}
]
}
Example: $not
{
"$not": {
{"QueueId": 1221}
}
}