---
title: "How to Connect MongoDB"
slug: "mongodb"
description: "Connect your data to MongoDB securely with Dataddo. Easily create a MongoDB destination with our step-by-step instructions. Data integration made easy."
updated: 2025-08-06T20:15:53Z
published: 2025-08-06T20:15:53Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dataddo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB

**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.

:::(Info) (**DATADDO TIP**)
Dataddo supports **MongoDB** as both a cloud-managed and an on-premises source or destination.
:::

## Prerequisites
:::(Error)
* You already have a MongoDB instance running with a public IP or hostname.
* You have configured [a MongoDB User](/docs/mongodb#in-mongodb) with `write` permissions.
* You have configured your network firewall to allow incoming connection from [Dataddo IPs](/docs/network-acl){target="_blank"}.
:::

## Authorize Connection to MongoDB

{{snippet.Destinations-Disclaimer}}

### In MongoDB
#### Create a MongoDB User and Set Permissions

1. Log into **MongoDB** shell.
2. Switch to the database you want to use, replace the example value `mydatabase`.
3. Run the command to create a new user.

```shell
use mydatabase
```

```shell
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](/docs/network-acl){target="_blank"}.
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](https://app.dataddo.com/service/new){target="_blank"} 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.
4. 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] Configure your destination using an existing SSH tunnel or [create a new one](/docs/ssh-tunnelling){target="_blank"}.
6. Click on **Save**.

## Create a New MongoDB Destination in Dataddo
{{snippet.DestinationGeneral}}

## Create a Flow to MongoDB
{{snippet.FlowGeneral}}

***
## 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:
```code
mongodb+srv://username:password@host/databaseName?options
```

For example:
```code
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.

{{snippet.Troubleshooting RelatedArticles Destinations}}
