Navigation

Built-In Actions

Built-in service actions are not associated with a specific service. MongoDB Stitch provides the various built-in service actions for use in pipelines.

Note

For details on a specific action, including syntax and examples, click on the specific operator to go to its reference page.

Action Description
binary Decodes base64 or hexadecimal encoded data and outputs as binary data stream.
encode Encodes incoming binary data into specified format.
expr Evaluates an expression against each input document and outputs the evaluated documents.
literal Explicitly defines its output documents.
match Filters its input documents.
namedPipeline Executes a named pipeline, given its name and arguments.
null Does nothing and outputs nothing.
project Determines which fields to include or exclude in the output documents.

Example

The following pipeline contains three stages which use built-in service actions.

  • The first stage uses the literal action to pass data to the second stage.
  • The second stage uses the match action to find documents in which the qty field is greater than 30.
  • The third stage creates a projection in which the unit price field is excluded from the stage output.
[
  {
    "action": "literal",
    "args": {
      "items": [
        { "type": "apples", "qty": 25, "unit price": 0.35 },
        { "type": "oranges", "qty": 50, "unit price": 0.65 }
      ]
    }
  },
  {
    "action": "match",
    "args": {
      "expression": {
        "qty": {
          "%gt": 30
        }
      }
    }
  },
  {
    "action": "project",
    "args": {
      "projection": {
        "unit price": 0
      }
    }
  }
]

The above pipeline operation produces the following output:

[
  {
    "type": "oranges",
    "qty": "50"
  }
]

The following pipeline example has two stages. The first passes two documents to the second stage, in which the built-in expr action concatenates two strings to form a greeting, and uses a let statement to access the current iteration of the items array.

[
  {
    "action": "literal",
    "args": {
      "items": [
        { "first_name": "Fred", "last_name": "Perry", "department": "sales" },
        { "first_name": "Mia", "last_name": "Perez", "department": "sales" }
      ]
    }
  },
  {
    "action": "expr",
    "let": {
      "name": "%%item.first_name"
    },
    "args": {
      "expression": {
        "greeting": {
          "%concat": [
            "Hello, ",
            "%%vars.name"
          ]
        }
      }
    }
  }
]

The above pipeline stage produces the following output:

[
  {
    "greeting": "Hello, Fred"
  },
  {
    "greeting": "Hello, Mia"
  }
]
←   Pipelines binary  →