- Reference >
- Operators >
- Aggregation Pipeline Operators >
- String Aggregation Operators >
- $strcasecmp (aggregation)
$strcasecmp (aggregation)¶
On this page
Definition¶
-
$strcasecmp¶ Performs case-insensitive comparison of two strings. Returns
- 1 if first string is “greater than” the second string.
- 0 if the two strings are equal.
- -1 if the first string is “less than” the second string.
$strcasecmphas the following syntax:The arguments can be any valid expression as long as they resolve to strings. For more information on expressions, see Expressions.
Behavior¶
$strcasecmp only has a well-defined behavior for strings of ASCII characters.
For a case sensitive comparison, see $cmp.
Example¶
Consider a inventory collection with the following documents:
The following operation uses the $strcasecmp operator to
perform case-insensitive comparison of the quarter field value to
the string "13q4":
The operation returns the following results: