Important Points About MongoDB $cmp Operator

  • The $cmp operator is used to compare two values or types and returns the result. It returns -1 if the first value is less than the second, 1 if the first value is greater than the second, and 0 if both values are equal.
  • The $cmp operator compares both value and type, using the specified BSON comparison order for values of different types.
  • The $cmp operator is used in the aggregation pipeline stages.

MongoDB $cmp Operator

The MongoDB $cmp operator compares two values or types and returns a result based on the comparison. It returns 1 if the first value is greater than the second, -1 if the first value is less than the second, and 0 if both values are equal.

Similar Reads

$cmp Operator in MongoDB

$cmp operator in MongoDB is one of the comparison expression operators. It is used in the aggregation pipeline stages....

Syntax

{ $cmp: [ , ] }...

MongoDB $cmp Operator Examples

Let’s look at some examples of the $cmp operator in MongoDB to understand the operator....

Important Points About MongoDB $cmp Operator

The $cmp operator is used to compare two values or types and returns the result. It returns -1 if the first value is less than the second, 1 if the first value is greater than the second, and 0 if both values are equal. The $cmp operator compares both value and type, using the specified BSON comparison order for values of different types. The $cmp operator is used in the aggregation pipeline stages....

Contact Us