$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.
Example
Consider an inventory
collection with the following documents:
The following operation uses the $cmp
operator to compare the qty
value with 250
:
The operation returns the following results: