MongoDB $toUpper Operator
To understand it better, let’s look at some examples of MongoDB $toUpper 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 $toUpper Operator Example
In this example, we are going to convert the value of the department field in uppercase and assign the result of the $toUpper operator as a value of dept field.
db.employee.aggregate([
... {$project: {dept: {$toUpper: "$department"}}}])
Using $toUpper Operator in the Embedded Document Example
In this example, we are going to convert the value of the name.first field in uppercase and assign the result of the $toUpper operator as a value of firstName field.
db.employee.aggregate([
... {$project: {firstName: {$toUpper: "$name.first"}}}])
MongoDB $toUpper Operator
MongoDB $toUpper operator converts the given string to uppercase.
Contact Us