Skip to Content

MongoDB Insert Activity

Introduction

A MongoDB Insert activity, using its MongoDB connection, inserts new data into a MongoDB collection and is intended to be used as a target to consume data in an operation.

Important

Inserting unescaped JSON or CSV documents can result in errors due to characters such as " and , being used as delimiters. To avoid this, pass the documents in XML format instead if character escaping is not possible.

Create a MongoDB Insert Activity

An instance of a MongoDB Insert activity is created from a MongoDB connection using its Insert 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 Insert activity can be edited from these locations:

Configure a MongoDB Insert Activity

Follow these steps to configure a MongoDB Insert 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 Insert Activity Configuration Step 1

  • Name: Enter a name to identify the activity. The name must be unique for each MongoDB Insert 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: Review the Data Schemas

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

MongoDB Insert Activity Configuration Step 2

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

    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 Insert 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
      insertRequest Request to insert documents into the database
      Documents Node representing the documents
      document Document content
    • Response:

      Response Schema Field/Node Description
      queryResponse Response from inserting into the database
      number_of_documents Number of documents (total)
      number_of_documents_processed Number of documents processed
      number_of_unprocessed_documents Number of documents unprocessed (total less processed)
      documents Node representing the documents
      isCreated True if document was successfully inserted
      message If successful, message is Document Successfully Created.
      documentId Document ID of newly-inserted document
      errors Node representing any errors
      documentId Document ID of document with error
      recordIndex Index of the document in the insert that had this error
      errorCode Error code
      errorMessage Error message returned with the error code
  • 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 Insert 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 Insert activities can be used as a target 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.