OPTIONS

$map (aggregation)

Definition

$map

$map applies a sub-expression to each item in an array and returns an array with the result of the sub-expression.

$map is available in the $project, $group, and $redact pipeline stages.

Example

Given an input document that resembles the following:

{ skews: [ 1, 1, 2, 3, 5, 8 ] }

And the following $project statement:

{ $project: { adjustments: { $map: { input: "$skews",
                                     as: "adj",
                                     in: { $add: [ "$$adj", 12 ] } } } } }

The $map would transform the input document into the following output document:

{ adjustments: [ 13, 13, 14, 15, 17, 20 ] }

See also

$let