- 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
_id
equal to1
, thescore: [ -1, 3 ]
as a whole meets the specified conditions since the element-1
meets the$lt: 2
condition and the element3
meets the$gt: 0
condition. - In the document with
_id
equal to2
, thescore: [ 1, 5 ]
as a whole meets the specified conditions since the element1
meets both the$lt: 2
condition and the$gt: 0
condition.
Geospatial¶
Use the following operators within the context of
$near
:
Use the following operators within the context of
$within
: