Query Operators
This page lists the supported MongoDB query and projection operators, with possible deviations.
Comparison
$eq
Example:
myfield:
$eq: "test"
This can also be written as:
myfield: "test"
$gt
Example:
myfield:
$gt: 100
$gte
Example:
myfield:
$gte: 100
$in
Example:
myfield:
$in:
- 1
- 2
- 3
$lt
Example:
myfield:
$lt: 100
$lte
Example:
myfield:
$lte: 100
$ne
Example:
myfield:
$ne: 10
$nin
Example:
myfield:
$nin:
- 1
- 2
- 3
Logical
$and
Example:
$and:
- x:
$gte: 0
- y:
$gte: 0
$not
Example:
myfield:
$not:
$lt: 0
$nor
Example:
$nor:
- x:
$lt: 0
- y:
$lt: 0
$or
Example:
$or:
- x:
$gt: 0
- y:
$gt: 0
Element
$exists
Example:
myfield:
$exists: true
$type
Example:
myfield:
$type: "string"
Evaluation
$expr
The MongoDB server only allows this operator at the top-level of an expression. This restriction doesn't apply in streaming mode, because no complicated query plan is needed. So, you can use it at any level of nesting, provided that the wrapped expression can be evaluated as a Boolean.
Example:
$expr:
$gt:
- "$field1"
- "$field2"
$mod
Example:
myfield:
$mod:
- 5
- 1
$regex
Example:
myfield:
$regex: "/^test/"
$options: "i"
This can be written shorter as:
myfield: "/^test/i"
Array
$all
The $elemMatch
operator is not supported within the $all
operator.
Example:
myfield:
$all:
- 1
- 2
- 3
$elemMatch
Example:
myfield:
$elemMatch:
name: "test"
$size
Example:
myfield:
$size: 3
Bitwise
$bitsAllClear
Example:
myfield:
$bitsAllClear:
- 2
- 3
$bitsAllSet
Example:
myfield:
$bitsAllSet:
- 2
- 3
$bitsAnyClear
Example:
myfield:
$bitsAnyClear:
- 2
- 3
$bitsAnySet
Example:
myfield:
$bitsAnySet:
- 2
- 3
Miscellaneous
$comment
Example:
x:
$mod:
- 2
- 0
$comment: "Select even values"