Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 17. Connecting to MongoDB


MongoDB is a distributed NoSQL database. A Fuse Online integration can obtain content from a MongoDB database or update content in a MongoDB database. To do this, create a MongoDB connection, and add it to an integration.

Important

Connecting to MongoDB is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.

Details for connecting to a MongoDB database are in the following topics:

17.1. Creating a connection to a MongoDB database

Create a MongoDB connection so that you can connect to a MongoDB database in an integration.

Prerequisites

  • You must know the host name for the MongoDB database that you want to connect to.
  • You must have a user name and password that authorizes access to the MongoDB database.

Procedure

  1. In Fuse Online, in the left panel, click Connections to display any available connections.
  2. In the upper right, click Create Connection to display connectors.
  3. Click the MongoDB connector.
  4. Configure the connection:

    1. In the Database host(s) field, specify one or more MongoDB database hosts that this connection can access. Separate multiple specifications of host:port with commas. Replace host with a host name, a virtual host name, or an IP address. For example: mongodb0.example.com:1234,mongodb1.example.com:1234.
    2. In the Username field, enter a user name that is authorized to access the database.
    3. In the Password field, enter the password for the user name that you specified.
    4. Optional. In the Administration database field, if the database has an administration database, enter the name of the MongoDB administration database that is used to grant access permission. A MongoDB administrator should let you know whether the database that you want to access has an administration database.
    5. Optional. In the Replica set name field, specify the name of the MongoDB replica set (cluster) that the connection can access.
    6. In the Database field, enter the name of the MongoDB database that contains the collection(s) that you want the connection to read.
  5. Click Validate. Fuse Online immediately tries to validate the connection and displays a message that indicates whether validation is successful. If validation fails, revise the input parameter(s) and try again.
  6. When validation is successful, click Next.
  7. In the Name field, enter your choice of a name that helps you distinguish this connection from any other connections. For example, you might enter MongoDB North.
  8. In the Description field, optionally enter any information that is helpful to know about this connection.
  9. Click Save to see that the connection you created is now available. If you entered the example name, you would see that MongoDB North appears as a connection that you can choose to add to an integration.

Next step

Add your MongoDB connection to an integration.

To trigger execution of an integration upon obtaining an update from a MongoDB database, add a MongoDB connection to a simple integration as its start connection. When the integration is running, the MongoDB connection monitors the database collection that you specified when you created the integration. The monitored collection must be a MongoDB capped collection. Insertion of a new document into the collection that the connection is configured to monitor, triggers execution of the integration. The MongoDB connection returns the collection update to the integration and this data is available to the next step in the integration.

Prerequisites

  • You created a MongoDB connection.
  • You know the name of the MongoDB capped collection that you want the connection to read.
  • You know the name of the MongoDB collection field that tracks incoming documents.
  • You know whether persistent tracking is enabled for the database that you want the connection to read from.
  • You know how to specify tail tracking information related to the data that you want the connection to read. MongoDB connections can use tail tracking information to resume an action after an unexpected connection termination. Tail tracking ensures that when the connection resumes its activity, it does not return duplicate data to the integration nor does it drop any data that needs to be returned to the integration.

Procedure

  1. In the Fuse Online panel on the left, click Integrations.
  2. Click Create Integration.
  3. On the Choose a connection page, click the MongoDB connection that is configured to access the database that you want the integration to obtain updates from.
  4. On the Choose an action page, select the Mongo consumer action.
  5. Configure the action:

    1. In the Collection name field, enter the name of the MongoDB collection that you want the connection to read.
    2. In the Collection field used to track incoming documents field, enter the name of the relevant MongoDB collection field. This field contains data that can be sorted, such as a date or an ID.
    3. Select the Persistent tracking enabled checkbox if persistent tracking is enabled for the database that you want the connection to read.
    4. In the Field used to store the tracking progress field, optionally specify the name of a field that is in the specified collection. A MongoDB administrator must have configured this field.
    5. In the DB used to store tail tracking field, optionally enter the name of the MongoDB database that contains tail tracking information.
    6. In the Collection used to store tail tracking field, optionally enter the name of the collection that contains tail tracking information.
    7. In the Field used to store tail tracking field, optionally, enter the name of the field that stores tail tracking information for the collection that this connection is reading.
    Note

    To identify the tail tracking field, you can specify the tail tracking database or tail tracking collection. With one of these pieces of information, the connection can find the tail tracking field.

  6. Click Next.

Result

The integration now has a start connection and Fuse Online is prompting you to choose the finish connection.

During execution, the connection returns the inserted document in JSON format.

17.3. Operating on documents in a MongoDB database

In an integration, you can retrieve, count, update, remove, and add documents to a MongoDB database. To do this, add a MongoDB connection to the middle of a flow or as a simple integration’s finish connection.

Prerequisites

  • You created a MongoDB connection.
  • You know the name of the MongoDB collection that you want the connection to operate on.
  • You are creating or editing an integration and Fuse Online is prompting you to add to the integration. Or, Fuse Online is prompting you to choose a finish connection.

Procedure

  1. On the Add to Integration page, click the plus sign where you want to add a MongoDB connection. Skip this step if you are adding a simple integration’s finish connection.
  2. Click the MongoDB connection that you want to use.
  3. On the Choose an action page, select the MongoDB producer action.
  4. Configure the action:

    1. In the Collection name field, enter the name of the collection that you want the connection to operate on.
    2. In the Operation to perform field, accept the Insert operation or click in the field to display the available actions. Click the action that you want the connection to perform. See the table below for a description of each operation.

      Each operation returns a response. If this is a finish connection, then the response is lost. Consequently, if this is a finish connection, the recommendation is to add a Log step to finish the integration instead. Configure the Log step to capture the response.

  5. Click Next.

Result

The connection appears in the integration visualization where you added it.

Next step

Add all connections to the flow. Add any other steps that process data. In this Technology Preview release, it is not possible to map source fields to MongoDB connection fields. Consequently, you must ensure that the data coming into the connection provides the required input for the selected operation. It is expected that a future release will support data mapping.

Expand
Table 17.1. Operation descriptions
OperationWhat it doesInputReturns

Count

Counts the number of documents that satisfy the input filter expression.

A JSON filter expression in the form of {"test":"unit"}. The operation counts the number of documents that have a test attribute value of unit.

JSON expression that specifies the number of documents that were found, for example, {"count":2}.

Find by id

Looks for a document that has the specified ID.

A string that contains the ID of interest.

JSON notation that specifies the document that has the ID.

Find all

Looks for all documents in the collection.

None

JSON notation that specifies all documents that are in the collection.

Insert

Adds a document to the collection.

JSON notation that specifies the document to add to the collection.

JSON notation that specifies the inserted document.

Remove

Removes a document from the collection.

A JSON expression in the form of {"test":"unit"}. The operation removes each document whose test attribute has a value of unit.

JSON expression that specifies the number of documents that were removed, for example, {"count":2}.

Save

Adds a document to the collection or updates a document in the collection.

JSON notation that specifies the document to add or update.

JSON notation that specifies the saved document.

Update

Updates a document in the collection.

An array of 2 arguments. The first argument is a filter expression that identifies the documents to update. The second argument is a MongoDB update statement that specifies how to update the documents. Update statement format is described in https://docs.mongodb.com/manual/reference/method/db.collection.update/. For example: [{"_id":11},{$set: {"test":"updated!"}}].

JSON notation that specifies the number of documents that were updated, for example: {"count":2}.

Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat