Query and Projection Operators of MongoDB
Query operators provide ways to locate data within the database
and projection operators modify how data is presented.
Comparison Operators
For comparison of different
BSON type values
in MongoDB |
in SQL |
Description |
$eq |
= |
Matches values that are equal to a specified value. |
$gt |
> |
Matches values that are greater than a specified value. |
$gte |
>= |
Matches values that are greater than or equal to a
specified value. |
$lt |
< |
Matches values that are less than a specified value. |
$lte |
<= |
Matches values that are less than or equal to a specified
value. |
$ne |
!= |
Matches all values that are not equal to a specified
value. |
$in |
in(x,y..) |
Matches any of the values specified in an array. |
$nin |
not in(x,y,…) |
Matches none of the values specified in an array. |
Logical Operators
in MongoDB |
in SQL |
Description |
$or |
or |
Joins query clauses with a logical OR returns all
documents that match the conditions of either clause. |
$and |
and |
Joins query clauses with a logical AND returns all
documents that match the conditions of both clauses. |
$not |
not |
Inverts the effect of a query expression and returns
documents that do not match the query expression. |
$nor |
|
Joins query clauses with a logical NOR returns all
documents that fail to match both clauses. |
Element Operators
Name |
Description |
$exists |
Matches documents that have the specified field. |
$type |
Selects documents if a field is of the specified type. |