MongoDB $toUpper Operator (original) (raw)

Last Updated : 5 May, 2026

The $toUpper operator converts string values to uppercase within the aggregation pipeline, enabling consistent text normalization, formatting, and case-insensitive operations.

Syntax

{ $toUpper: }

Use Cases for MongoDB $toUpper Operator

The $toUpper operator is versatile and can be used in various scenarios:

Examples of MongoDB $toUpper Operator

Sample collection employee in the GeeksforGeeks database, where each document contains employee details like name and department.

Screenshot-2026-02-14-134434

Example 1: Using $toUpper Operator

Convert the value of the department field in uppercase and assign the result of the $toUpper operator as a value of dept field. This can be useful when we need to display or compare department names in a consistent case.

db.employee.aggregate([
{
$project: {
dept: { toUpper:"toUpper: "toUpper:"department" }
}
}
])

**Output:

Screenshot-2026-02-14-134616

Example 2: Using $toUpper in the Embedded Document

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:"toUpper: "toUpper:"name.first" }
}
}
])

**Output:

Screenshot-2026-02-14-134830

Usage of $toUpper Operator

Here are some uses listed: