MongoDB $toLower Operator Examples
To understand it better, let’s look at some examples of MongoDB $toLower Operator.
In the following examples, we are working with:
Database: w3wiki
Collection: employee
Document: three documents that contain the details of the employees in the form of field-value pairs.
Using $toLower Operator Example
In this example, we are going to convert the value of the department field in lowercase.
Query:
db.employee.aggregate([
... {$match: {"name.first": "Aman"}},
... {$project: {dept: {$toLower: "$department"}}}])
Output:
Using $toLower Operator in embedded documents Example
In this example, we are going to convert the value of the name.first field in lowercase.
db.employee.aggregate([
... {$match: {department: "Development"}},
... {$project: {name: {$toLower: "$name.first"}}}])
MongoDB $toLower Operator
MongoDB $toLower operator converts the given string to lowercase.
Contact Us