Navigation

project

On this page

Definition

project

Determines which fields to include or exclude in the output documents.

The project action cannot be in the first stage of a pipeline. The stage preceding the project action stage must output documents; for example, a built-in action literal stage.

The project action stage has the following syntax:

Tip

In the stages, the action arguments can make use of variables (%%vars) defined for the stage as well as defined constants and expansions.

{"service": "", "action": "project", "args": {"projection": <document> } }

The project action has the following argument:

Argument Type Description
projection document

A document that specifies field inclusions or field exclusions:

  • To specify the fields to include in the output document, list the fields in the projection document with a value 1 or true:

    { <field1>: 1, <field2>: 1, ... }

  • To specify the fields to exclude in the output document, list the fields in the projection document with a value 0 or false:

    { <field1>: 0, <field2>: 0, ... }

A projection document cannot specify both field inclusions and field exclusions.

Example

Consider the following pipeline of two stages:

[
  {"service": "", "action": "literal", "args": {"items": [{"x": 5, "y": 10}, {"x": 10, "y": 10}]}},
  {"service": "", "action": "project", "args": {"projection": { "x": 1 }}}
]

Stage1: The literal stage outputs the following documents:

{"x": 5, "y": 10}
{"x": 10, "y": 10}

The two documents are input to Stage 2.

Stage2: The projection stage outputs the document with only the x field in the documents:

{"x": 5}
{"x": 10}
←   match reader  →