Skip to Content

MongoDB Query Activity

Introduction

A MongoDB Query activity, using its MongoDB connection, retrieves data from a MongoDB collection and is intended to be used as a source to provide data in an operation.

Create a MongoDB Query Activity

An instance of a MongoDB Query activity is created from a MongoDB connection using its Query activity type.

To create an instance of an activity, drag the activity type to the design canvas or copy the activity type and paste it on the design canvas. For details, see Create an Activity Instance in Component Reuse.

An existing MongoDB Query activity can be edited from these locations:

Configure a MongoDB Query Activity

Follow these steps to configure a MongoDB Query activity:

Step 1: Enter a Name and Select a Collection

In this step, provide a name for the activity and select a collection. Each user interface element of this step is described below.

MongoDB Query Activity Configuration Step 1

  • Name: Enter a name to identify the activity. The name must be unique for each MongoDB Query activity and must not contain forward slashes / or colons :.

  • Select an Object: This section displays collections available in the MongoDB endpoint.

    • Selected MongoDB Object: After a collection is selected, it is listed here.

    • Search: Enter any part of the collection name into the search box to filter the list of collections. The search is not case-sensitive. If collections are already displayed within the table, the table results are filtered in real time with each keystroke. To reload collections from the endpoint when searching, enter search criteria and then refresh, as described below.

    • Refresh: Click the refresh icon Refresh icon or the word Refresh to reload collections from the MongoDB endpoint. This may be useful if collections have been added to MongoDB. This action refreshes all metadata used to build the table of collections displayed in the configuration.

    • Selecting a Collection: Within the table, click anywhere on a row to select an collection. Only one collection can be selected. The information available for each collection is fetched from the MongoDB endpoint:

      • Name: The name of the collection.

      • Description: The description of the collection.

    Tip

    If the table does not populate with available collections, the MongoDB connection may not be successful. Ensure you are connected by reopening the connection and retesting the credentials.

  • Save & Exit: If enabled, click to save the configuration for this step and close the activity configuration.

  • Next: Click to temporarily store the configuration for this step and continue to the next step. The configuration will not be saved until you click the Finished button on the last step.

  • Discard Changes: After making changes, click to close the configuration without saving changes made to any step. A message asks you to confirm that you want to discard changes.

Step 2: Specify Settings

In this step, specify the Filter, Limit, Projection Type, and Projection. Each user interface element of this step is described below.

MongoDB Query Activity Configuration Step 2

Tip

Fields with a variable icon Variable icon support using global variables, project variables, and Jitterbit variables. Begin either by typing an open square bracket [ into the field or by clicking the variable icon to display a list of the existing variables to choose from.

  • Filter: Enter a filter (in MongoDB Extended JSON format) to use when fetching documents of the specified collection.

  • Limit: Enter the maximum number of documents to fetch from the collection.

  • Projection Type: Select a projection type, either Include or Exclude:

    • Include: Returns certain fields (specified within the Projection field) in the response.

    • Exclude: Excludes certain fields (specified in the Projection field) from the response.

  • Projection: Enter a projection to include or exclude fields returned in the Query response. Multiple values must be separated by a comma.

  • Sort: Define the sort order of this activity's response. Click the add icon add icon to add a Property and Ordering Type to the table below:

    • Property: Enter the name of the field being sorted.
    • Ordering Type: Specify whether the documents containing the field are sorted in ascending order (1) or descending order (-1).

    To save the row, click the submit icon submit icon in the rightmost column.

    To edit or delete a single row, hover over the rightmost column and use the edit icon edit icon or delete icon delete icon.

    To delete all rows, click Clear All.

  • Back: Click to temporarily store the configuration for this step and return to the previous step.

  • Next: Click to temporarily store the configuration for this step and continue to the next step. The configuration will not be saved until you click the Finished button on the last step.

  • Discard Changes: After making changes, click to close the configuration without saving changes made to any step. A message asks you to confirm that you want to discard changes.

Step 3: Review the Data Schemas

Any request or response schemas are displayed. Each user interface element of this step is described below.

MongoDB Query Activity Configuration Step 3

  • Data Schemas: These data schemas are inherited by adjacent transformations and are displayed again during transformation mapping.

    Note

    Data supplied in a transformation takes precedence over the activity configuration.

    The MongoDB connector uses the MongoDB Java Driver v4.1. Refer to the driver documentation and the MongoDB reference for information on the schema nodes and fields.

    The Query activity uses XML in both its request and response schemas.

    The request and response data schemas consist of these nodes and fields:

    • Request:

      Request Schema Field/Node Description
      queryRequest Request to query the database
      filter A filter in MongoDB Extended JSON format used to match the documents in the selected collection
      projection The projection string
      limit Maximum number of documents to fetch from the collection
      projectionType The projection type, either include or exclude
      sort The sort order of this activity's response
      key Enter the field to be sorted
      value Specify whether the documents containing the field are sorted in ascending order (1) or descending order (-1)
      aggregrate Node containing the specifications of an aggregation operation
      unwind Enter the field to unwind
      match Node containing the key-value pair of the conditions for the match pipeline stage
      key Enter the field being queried
      value Enter the desired value of the field being queried
      sortAggregrate Node containing the sort order of the aggregate results
      key Enter the field to be sorted
      value Specify whether the documents containing the field are returned in ascending order (1) or descending order (-1)
      project Node containing conditions for the project pipeline stage
      exclude Enter the field to be excluded in the response
      include Enter the field to be included in the response
      group Node containing conditions for the group pipeline stage
      key Enter the group key
      value Enter group value
      accumulator Enter the accumulator
      nameNewField Enter the name of the field being added
      out Enter the collection for the out pipeline stage
    • Response:

      Response Schema Field/Node Description
      queryResponse Response from querying the database
      records Number of documents (records) returned
      documents Node representing the documents
      document Document content
  • Refresh: Click the refresh icon Refresh icon or the word Refresh to regenerate schemas from the MongoDB endpoint. This action also regenerates a schema in other locations throughout the project where the same schema is referenced, such as in an adjacent transformation.

  • Back: Click to temporarily store the configuration for this step and return to the previous step.

  • Finished: Click to save the configuration for all steps and close the activity configuration.

  • Discard Changes: After making changes, click to close the configuration without saving changes made to any step. A message asks you to confirm that you want to discard changes.

Next Steps

After configuring a MongoDB Query activity, complete the configuration of the operation by adding and configuring other activities, transformations, or scripts as operation steps. You can also configure the operation settings, which include the ability to chain operations together that are in the same or different workflows.

Menu actions for an activity are accessible from the project pane and the design canvas. For details, see Activity Actions Menu in Connector Basics.

MongoDB Query activities can be used as a source with these operation patterns:

To use the activity with scripting functions, write the data to a temporary location and then use that temporary location in the scripting function.

When ready, deploy and run the operation and validate behavior by checking the operation logs.