- Reference >
- Query, Update, and Projection Operators Quick Reference
Query, Update, and Projection Operators Quick Reference¶
On this page
This document contains a list of all operators used with MongoDB in version 2.2. See Core MongoDB Operations (CRUD) for a higher level overview of the operations that use these operators, and Query, Update, Projection, and Aggregation Operators for a more condensed index of these operators.
Query Selectors¶
Comparison¶
Note
To express equal to (e.g. =) in the MongoDB query language,
use JSON { key:value } structure. Consider the following
prototype:
For example:
This query selects all the documents the where the a field
holds a value of 42.
You may combine comparison operators to specify ranges:
This statement returns all documents with field between
value1 and value2.
Note
If the field contains an array and the query has multiple conditional operators, the field as a whole will match if either a single array element meets the conditions or a combination of array elements meet the conditions.
Example
Query a field that contains an array.
A collection students contains the following documents where the
score field contains an array of values:
Then, the following query:
Will match the following documents:
- In the document with
_idequal to1, thescore: [ -1, 3 ]as a whole meets the specified conditions since the element-1meets the$lt: 2condition and the element3meets the$gt: 0condition. - In the document with
_idequal to2, thescore: [ 1, 5 ]as a whole meets the specified conditions since the element1meets both the$lt: 2condition and the$gt: 0condition.
Geospatial¶
Use the following operators within the context of
$near:
Use the following operators within the context of
$within: