- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $cmp (aggregation)
$cmp (aggregation)¶
On this page
Definition¶
-
$cmp
¶ Compares two values and returns:
-1
if the first value is less than the second.1
if the first value is greater than the second.0
if the two values are equivalent.
The
$cmp
compares both value and type, using the specified BSON comparison order for values of different types.$cmp
has the following syntax:For more information on expressions, see Expressions.