Query Operators
Query operators can be used to construct query conditions in order to find data. Query operators are typically applied to a property and take a value or a document defining the conditions of the operation.
For example:
Or:
Or, in the case of logical operators (e.g. $and
, $or
), the operator takes an array of expressions:
Usage
Query operators can be used in a where
query argument or in a $match
pipeline stage .
When used in a where
query argument, the request looks similar to the following:
When used in a $match
pipeline stage, the request looks similar to the following:
Query Operator Types
Type
Description
Comparison Operators
For filtering results based on value comparisons.
Logical Operators
Join query clauses together or invert the meaning of a query expression
Evaluation Operators
Filter results based on the result of a regular expression
Geospatial Operators
Find locations within a distance of a central location.
Array Operators
Match on arrays, elements in an array, or size of arrays.
Comparison Operators
Operator
Description
Example
$eq
Selects documents where the value of the property is equal to the passed in value.
{“c_bpm”: {“$eq”: 70}}
$gt
Selects documents where the value of the property is greater than the passed in value.
{“c_bpm”: {“$gt”: 70}}
$gte
Selects documents where the value of the property is greater than or equal to the passed in value.
{“c_bpm”: {“$gte”: 70}}
$lt
Selects documents where the value of the property is lesser than the passed in value.
{“c_bpm”: {“$lt”: 70}}
$lte
Selects documents where the value of the property is lesser than or equal to the passed in value.
{“c_bpm”: {“$lte”: 70}}
$ne
Selects documents where the value of the property is not equal to the passed in value.
{“c_bpm”: {“$ne”: 70}}
$in
Selects documents where the property matches any of the passed in values.
{“c_bpm”: {“$in”: [65, 66, 67, 68, 69, 70]}}
$nin
Selects documents where the property matches none of the passed in values.
{“c_bpm”: {“$nin”: [65, 66, 67, 68, 69, 70]}}
Logical Operators
Operator
Description
Example
$and
Selects documents where all passed in conditions are met.
{“$and”: [{“c_bpm”: {“$gt”: 70}}, {“c_bpm”: {“$lt”: 100}}] }
$or
Selects documents where any passed in conditions are met.
{“$or”: [{“c_bpm”: {“$gt”: 70}}, {“c_bmi”: {“$gt”: 24.9}}] }
$not
Evaluates to true if the property or expression evaluates to false.
{“$not”: “c_active”}
$nor
Selects documents where none of the passed in conditions are met.
{“$nor”: [{“c_bpm”: {“$gt”: 70}}, {“c_bmi”: {“$gt”: 24.9}}] }
Evaluation Operators
Operator
Description
Example
$regex
Selects documents where the string property matches the passed in regular expression.
{“name.first”: {“$regex”: “/^samplename/i”}}
Geospatial Operators
Operator
Description
Example
$within
Selects documents with geospatial data that exists entirely within a specified shape.
{"c_location": {"$within": {"$center": [-122.143019, 37.441883], "$radius": 10}}}
Array Operators
Operator
Description
Example
$all
Selects documents where the array property contains all of the passed in values.
{“roles”: {“$all”: [“000000000000000000000007”, “0123456789ab0123456789ab”]}}
$elemMatch
Selects documents where all properties of an array of document properties match the passed in expression. $elemMatch does not limit the results within the array, but filters the entire document for contained entries.
{“c_docs”: {“$elemMatch”: {“c_foo”: “yes”, “c_bar”: true}}}
$size
Selects documents where the size of the array property matches the passed in values.
{“c_arr”: {“$size”: 20}}
Last updated