Contact Free trial Login

Use Studio to Configure MongoDB Connector 6.3 - Mule 4

Anypoint Studio (Studio) editors help you design and update your Mule applications, properties, and configuration files.

To add and configure a connector in Studio:

If you are new to configuring connectors in Studio, see Use Studio to Configure a Connector. If, after reading this topic, you need additional information about the connector fields, see the MongoDB Connector Reference.

Create a Mule Project

In Studio, create a new Mule project in which to add and configure the connector:

  1. In Studio, select File > New > Mule Project.

  2. Enter a name for your Mule project and click Finish.

Add the Connector to Your Mule Project

Add <connector name> to your Mule project to automatically populate the XML code with the connector’s namespace and schema location and add the required dependencies to the project’s pom.xml file:

  1. In the Mule Palette view, click (X) Search in Exchange.

  2. In Add Modules to Project, type mongodb in the search field.

  3. Click MongoDB in Available modules.

  4. Click Add.

  5. Click Finish.

Adding a connector to a Mule project in Studio does not make that connector available to other projects in your Studio workspace.

Configure an Input Source for the Connector

Configure an input source for the connector, such as the Object Listener operation, HTTP Listener, or Scheduler. The Object Listener operation polls the given MongoDB collection for new documents that apply to the filter and invokes your app when it finds one.

For example, to configure HTTP Listener, follow these steps:

  1. In the Mule Palette view, select HTTP > Listener.

  2. Drag Listener to the Studio canvas.

  3. On the Listener configuration screen, optionally change the value of the Display Name field.

  4. Specify a value for the Path field.

  5. Click the plus sign (+) next to the Connector configuration field to configure a global element that can be used by all instances of HTTP Listener in the app.

  6. On the General tab, specify connection information.

  7. On the TLS tab, optionally specify TLS information.

  8. On the Advanced tab, optionally specify reconnection information, including a reconnection strategy.

  9. Click Test Connection to confirm that Mule can connect with the specific server.

  10. Click OK.

Add a Connector Operation to the Flow

When you add a connector operation to your flow, you immediately define a specific operation for that connector to perform.

To add an operation for MongoDB, follow these steps:

  1. In the Mule Palette view, select MongoDB and then select the desired operation.

  2. Drag the operation onto the Studio canvas to the right of the input source.

Configure a Global Element for the Connector

When you configure a connector, it’s best to configure a global element that all instances of that connector in the app can use. Configuring a global element requires you to provide the authentication credentials the connector uses to access the target MongoDB system.

To configure the global element for MongoDB Connector, follow these steps:

  1. On the Global Elements tab, click Create.

  2. Expand Connector Configuration and search for MongoDB config.

  3. Click OK.

  4. Enter a value for the following properties:

    • Servers (host:port)

      Servers where your MongoDB instance is located, as specified by one or more host:port pairs. The default value is localhost:27017. Follow these steps to add one or more host:port instances:

      1. Select Edit inline.

      2. Click the green plus sign (+).

      3. Add the host:port instance and click Finish.

      4. Repeat steps 2 and 3 for each host:port instance you want to add.

    • Database

      Database that sends and retrieves data from the MongoDB instance

    • Username

      Username to access the MongoDB instance

    • Password

      Corresponding password

Use the MongoDB configuration with Spring property placeholders for the Connection field values when you plan to deploy your application to CloudHub or to Mule runtime engine. You can hard code your connection credentials in the global element properties if you are in the development stage and want to accelerate the development process.

Global Configuration with SSL (Optional)

MongoDB Connector v6.0.0 and later supports the use of SSL, if your MongoDB instance supports it. To set up the global configuration for SSL, select the TLS context field in the Security tab in your MongoDB connection.

Logging

By default, logging is enabled via SLF4J API. The driver uses the following logger names:

  • org.mongodb.driver, the root logger

    • cluster, for logs related to monitoring of the MongoDB servers to which the driver connects

    • connection, for logs related to connections and connection pools

    • protocol, for logs related to protocol message sent to and received from a MongoDB server

      • insert, for logs related to insert messages and responses

      • update, for logs related to update messages and responses

      • delete, for logs related to delete messages and responses

      • query, for logs related to query messages and responses

      • getmore, for logs related to getmore messages and responses

      • killcursor, for logs related to killcursor messages and responses

      • command, for logs related to command messages and responses

    • uri, for logs related to connection string parsing

    • management, for logs related to JMX

Next Steps

After configuring Studio, see the Examples topic for more configuration ideas.