Skip to main content

Connect

Establishes a connection to a MongoDB database server using database credentials and returns a client ID for use in subsequent MongoDB operations.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Options

  • Credentials - Database credentials (Category 5) containing connection information:
    • server - MongoDB server hostname or IP address
    • port - Server port (defaults to 27017 if not specified)
    • database - Authentication database name (optional)
    • username - Database username (optional, for authenticated connections)
    • password - Database password (optional, for authenticated connections)

Output

  • Client Id - A unique identifier for the MongoDB client connection that must be used in subsequent MongoDB operations.

How It Works

The Connect node is the first step when using the explicit connection approach in MongoDB automation flows. When executed, the node:

  1. Retrieves database credentials from the provided credential object
  2. Constructs the MongoDB connection URL based on the credential fields
  3. Establishes a connection to the MongoDB server
  4. Verifies the connection with a ping operation
  5. Stores the client connection internally with a unique client ID
  6. Returns the client ID for use in other MongoDB nodes

Connection URL Format

The node automatically constructs the connection URL based on your credentials:

With Authentication:

mongodb://username:password@host:port/?authSource=database

Without Authentication:

mongodb://host:port/

Requirements

  • A running MongoDB server (local or remote)
  • Valid database credentials stored in Robomotion
  • Network access to the MongoDB server
  • Proper authentication if the server requires it

Error Handling

The node will return specific errors in the following cases:

  • ErrInvalidArg - Database credentials are missing or server hostname is empty
  • ErrConnection - Cannot connect to the MongoDB server or ping fails

Usage Notes

  • The Connect node should be executed before any other MongoDB operations when using the client ID approach
  • The returned Client Id must be passed to subsequent MongoDB nodes
  • Port defaults to 27017 (MongoDB default) if not specified in credentials
  • Authentication database (authSource) is optional and only used when username/password are provided
  • Each Connect node creates a new client connection that should be cleaned up with a Disconnect node
  • The connection is maintained in memory until explicitly disconnected or the flow stops

Alternative Approach

Most MongoDB nodes also accept credentials directly as an option, allowing you to perform operations without using the Connect/Disconnect pattern. This is useful for single operations but less efficient for multiple operations on the same connection.

Best Practices

  • Use a single Connect node at the beginning of your flow for better connection management
  • Always pair Connect with Disconnect nodes to properly clean up resources
  • Store database credentials securely in the Robomotion vault
  • Use the client ID approach when performing multiple operations on the same database
  • Handle connection errors appropriately to prevent flow failures
  • Verify network connectivity and firewall settings if connection fails

Example Usage

Scenario: Connect to a MongoDB server for multiple operations

  1. Add a Connect node at the start of your flow
  2. Configure credentials with server details:
    • server: "localhost"
    • port: "27017"
    • username: "admin"
    • password: (from vault)
    • database: "admin"
  3. Store the returned Client Id in a message variable
  4. Use this Client Id in subsequent database operations
  5. Add a Disconnect node at the end to close the connection

Scenario: Connect to MongoDB Atlas (cloud)

  1. Configure credentials with MongoDB Atlas connection string components:
    • server: "cluster0.example.mongodb.net"
    • port: "27017"
    • username: "atlasuser"
    • password: (from vault)
    • database: "admin"
  2. The node will handle the connection to the cloud cluster