The $toLower operator converts string values to lowercase within MongoDB’s aggregation pipeline to lowercase within MongoDB’s aggregation pipeline, enabling consistent text normalization and case-insensitive comparisons for reliable search and formatting.
Converts all alphabetic characters in a string to lowercase.
Accepts any expression that resolves to a string.
Returns an empty string ("") if the input resolves to null.
Behavior depends on MongoDB’s collation and Unicode handling; for language-specific or locale-aware transformations, use collation.
Designed for aggregation stages only (e.g., $project, $addFields, $match with $expr), not for direct update operations.
Syntax
{ $toLower: <expression> }
<expression>: Any valid expression that evaluates to a string.
If the expression resolves to null, $toLower returns an empty string ("").
Examples of Using MongoDB $toLower Operator
In the following examples, we are working with:
Database: GeeksforGeeks
Collection: employee
Document: Three documents that contain the details of the employees in the form of field-value pairs.