Aggregation Operators
The aggregation operators are used to aggregate data in a conditional query.
The following aggregation operators are supported:
Operator | Description |
---|---|
$each_n | Keeps each N-th record after previous condition |
$each_t | Keeps a record after the previous condition once in every N seconds |
$limit | Limits the number of records to be processed in the query |
$each_n
The $each_n
operator is used to keep each N-th record after the previous condition.
Syntax
{
"$each_n": [ <expression as integer> ]
}
Behavior
The operator evaluates the first expression as an integer and uses it to determine the step size for keeping records.
Examples
Filter records with a score greater than 10, then return every 5th record from the result:
{
"&score": { "$gt": 10 },
"$each_n": 5
}
Select every 5th record, then return those with a score greater than 10:
{
"$each_n": 5,
"&score": { "$gt": 10 }
}
$each_t
The $each_t
operator keeps a record if its timestamp is at least the specified number of seconds after the previous matching record.
Syntax
{
"$each_t": [ <expression as float> ]
}
Behavior
The operator evaluates the first expression as a float and uses it to determine the time in seconds for keeping records.
Examples
Filter records with a score greater than 10, then return only those that are at least 5 seconds apart.
{
"&score": { "$gt": 10 },
"$each_t": 5
}
Keep only records at least 5 seconds apart, then filter for scores greater than 10:
{
"$each_t": 5,
"&score": { "$gt": 10 }
}
$limit
The $limit
operator is used to limit the number of records to be processed in the query.
Syntax
{
"$limit": [ <expression as integer> ]
}
Behavior
The operator evaluates the first expression as an integer and uses it to limit the number of records to be processed in the query. The operator is applied after the previous condition, so it limits the number of records that match the previous condition.
Examples
Limit the number of records whose score is greater than 10 to 5:
{
"&score": { "$gt": 10 },
"$limit": 5
}
Find records with a score greater than 10 in the first 5 records:
{
"$limit": 5,
"&score": { "$gt": 10 }
}