Pipeline Practice

MongoDB $map

Transform every element in an array and return a new array.

Choose the input array, give the current element a variable name, and return the expression that should become each new element.

Array expressions inspect or transform an array without creating a separate document for every element. These are supported in the playground for further practice.

Course use: Supported in the playground.

Example pipeline syntax

{ $map: {
  input: "$items",
  as: "item",
  in: "$item.productId"
} }