MongoDB
  • 3 Minutes to read
  • Dark
    Light

MongoDB

  • Dark
    Light

Article Summary

MongoDB is an open-source NoSQL database management system that provides a flexible, document-oriented approach to storing and retrieving data. It is designed to handle unstructured or semi-structured data and is widely used for building scalable and high-performance applications.

Prerequisites

  • You already have a MongoDB instance running with a public IP or hostname.
  • You have configured a MongoDB User with write permissions.
  • You have configured your network firewall to allow incoming connection from Dataddo IPs.

Authorize Connection to MongoDB

Please keep in mind that this guide provides general instructions, and your individual setup might need a different approach or some extra steps. Always take your organization's security guidelines into account when you're making these changes. Additionally, it's a good idea to seek assistance from a database administrator or an IT professional to make sure everything is set up correctly.

In MongoDB

Create a MongoDB User and Set Permissions

  1. Log into MongoDB shell.
  2. Switch to the database you want to use. In the example below we are using mydatabase.
  3. Run a command to create a new user.
use mydatabase
db.createUser(
  {
    user: "dataddo",
    pwd: "***",
    roles: [ { role: "readWrite", db: "mydatabase" } ]
  }
)

Allow Network Connection

For this destination, whitelisting IP addresses is not available in the database system. Instead, you can configure the network access at the firewall level. Here are the general steps:

  1. Identify the firewall that's protecting your service. This could be a Windows or Linux firewall running on the server itself, or it could be a network firewall.
  2. Open the firewall's configuration settings. This process will vary depending on the type of your firewall.
  3. Look for the setting that allows you to define inbound rules or policies.
  4. Create a new rule or policy that allows inbound traffic on the port that the service is using (the default is 27017) from the Dataddo IP addresses.
  5. Save your changes and test the connection from Dataddo to make sure everything is working as intended.

For MongoDB, the ability to whitelist IP addresses isn't built into the database system. Instead, you can control network access at the firewall level.

In Dataddo

  1. Go to the Authorizers tab, click on Authorize New Service and select MongoDB.
  2. The How you want connect to Mongo value is preset to Credentials. You can choose on DSN providing you have it.
  3. You will be asked to fill the following fields
    1. Protocol: Protocol used for connection. In standalone MongoDB deployments use mongo.
    2. Server IP or Hostname: Public IP or hostname of your MongoDB instance.
    3. Port: Port to connect to MongoDB. The default value is 27017.
    4. Authentication database: Database that you want to use for authentication, i.e. to which the user is associated to. In most of the cases this will be admin or the same value as you put in database.
    5. Database: Database to which you want to connect.
    6. User: Username as configured in Create a MongoDB user step.
    7. Password: Password as configured in Create a MongoDB user step.
  4. [Optional] You can also configure the connection via SSH tunnel. To do so, please follow these steps.
  5. Click on Save.

Create a New MongoDB Destination in Dataddo

  1. On the Destinations page, click on the Create Destination button and select the destination from the list.
  2. Select your authorizer from the drop-down menu.
  3. Name your destination and click on Save.
Need to authorize another connection?

Click on Add new Account in drop-down menu during authorizer selection and follow the on-screen prompts. You can also go to the Authorizers tab and click on Add New Service.

Create a Flow to MongoDB

  1. Navigate to Flows and click on Create Flow.
  2. Click on Connect Your Data to add your source(s).
  3. Click on Connect Your Data Destination to add the destination.
  4. Choose the write mode and fill in the other required information.
  5. Check the Data Preview to see if your configuration is correct.
  6. Name your flow and click on Create Flow to finish the setup.


Troubleshooting

Connection Error

If you experience a connection error, please

  1. Check your connection string and
  2. Make sure the database name is there.

The connection string should be in the following format:

mongodb+srv://username:password@host/databaseName?options

For example:

mongodb+srv://jack:1234myPassword@cluster.test.mongodb.net/myDatabase?retryWrites=true&w=majority

DNS on No such host Error

lookup ... on ... no such host

If you experience a DNS or No such host error, it means that the hostname of your server is not accesible through the internet, please

  1. Check your connection string and
  2. Make sure the hostname is that is publicly accessible via internet is present.


Was this article helpful?

What's Next