Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (51 sloc) 1.76 KB
======================
$toUpper (aggregation)
======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. expression:: $toUpper
Converts a string to uppercase, returning the result.
:expression:`$toUpper` has the following syntax:
.. code-block:: javascript
{ $toUpper: <expression> }
The argument can be any :ref:`expression <aggregation-expressions>`
as long as it resolves to a string. For more information on
expressions, see :ref:`aggregation-expressions`.
If the argument resolves to null, :expression:`$toUpper` returns an
empty string ``""``.
Behavior
--------
.. |exp-has| replace:: :expression:`$toUpper` only has
.. include:: /includes/intro-aggregation-string.rst
Example
-------
Consider a ``inventory`` collection with the following documents:
.. code-block:: javascript
{ "_id" : 1, "item" : "ABC1", quarter: "13Q1", "description" : "PRODUCT 1" }
{ "_id" : 2, "item" : "abc2", quarter: "13Q4", "description" : "Product 2" }
{ "_id" : 3, "item" : "xyz1", quarter: "14Q2", "description" : null }
The following operation uses the :expression:`$toUpper` operator return
uppercase ``item`` and uppercase ``description`` values:
.. code-block:: javascript
db.inventory.aggregate(
[
{
$project:
{
item: { $toUpper: "$item" },
description: { $toUpper: "$description" }
}
}
]
)
The operation returns the following results:
.. code-block:: javascript
{ "_id" : 1, "item" : "ABC1", "description" : "PRODUCT 1" }
{ "_id" : 2, "item" : "ABC2", "description" : "PRODUCT 2" }
{ "_id" : 3, "item" : "XYZ1", "description" : "" }
You can’t perform that action at this time.