---
title: "MongoDB® - Configure an instance to accept incoming connections"
description: "Learn how to configure your MongoDB® instance to accept incoming connections."
url: https://docs.us.ovhcloud.com/en/public-cloud/databases/mongodb-configure-instance-accept-incoming-connections
lang: en
---
> For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt.

# MongoDB® - Configure an instance to accept incoming connections

**Learn how to configure your MongoDB® instance to accept incoming connections.**

Cloud Databases allow you to focus on building and deploying cloud applications while OVHcloud takes care of the database infrastructure and maintenance in operational conditions.

 

## Requirements

- A [Public Cloud project](https://us.ovhcloud.com/public-cloud/) in your OVHcloud account
- Access to the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/#/hub)
- A MongoDB[®](#go-further) database running on your OVHcloud Cloud Databases ([this guide](https://docs.us.ovhcloud.com/en/public-cloud/databases/getting-started.md) can help you to meet this requirement)

 

## Instructions

### Configure your MongoDB® instance to accept incoming connections

Before making a connection, we must verify that our MongoDB® instance is correctly configured.

Log in to your [OVHcloud Control Panel](https://manager.us.ovhcloud.com/#/hub) and select your MongoDB® instance via the `Public Cloud` and `Databases` menus.

 

#### Step 1: Verify your user roles and password

Select the `Users` tab. Verify that you have a user with sufficient rights and a configured password. If you don't remember the user's password, you can either create a new user or regenerate the password of an existing user. Be careful! By doing so, you will need to update all the places where you already use this user/password pair.

To create a new user, click `+ Add user`.

We provide official MongoDB® built-in roles. Please read the [official MongoDB® documentation](https://docs.mongodb.com/manual/reference/built-in-roles/) to select the right roles for your use case.

In our example, we will create a new user called **foo** with the role `userAdmin` on the `bar` database and the role `readWriteAnyDatabase` on any database (admin).

Click `Create User`.

After a few seconds, the user is ready (with an "Enabled" status), and you can then reset and note its password.

 

#### Step 2: Authorize incoming connections from the MongoDB® client

In this step, select the `Configuration` tab, add the IP(s) you wish to authorize, and click the _add_ `+` button. By default, a Cloud Database does not accept any form of connection from the outside world. This way, we can help prevent intrusive connection attempts.

Select `Save changes` when you are finished.

**Note:**

If you want to allow any connections from the outside, you can enter the IP 0.0.0.0/0. Please use it carefully. Every IP will be authorized.

 

### Get your connection information (URI)

Select the `Dashboard` tab. In the **Connection information** section, copy the Service URI.

You can specify the MongoDB® connection string using either:

- _Service -> mongoDB_ for the Standard Connection String format **(soon deprecated)**.
- _Service -> mongodbSrv_ for the DNS Seed List Connection String format.

**Note:**

MongoDB® 3.6 introduced the concept of a seed list that is specified using DNS records, specifically SRV and TXT records. This allows a client to connect to a replica set even if one of the nodes that the client specifies is unavailable.\
The use of SRV records eliminates the requirement for every client to pass in a complete set of state information for the cluster. Instead, a single SRV record identifies all the nodes associated with the cluster (and their port numbers) and an associated TXT record defines the options for the URI.\
_Learn more [here](https://www.mongodb.com/docs/manual/reference/connection-string/)_.

 

mongodb

- It should be similar to this when you have a single node:

```
mongodb://<username>:<password>@<hostname>/admin?tls=true
```

- And like this when you have a MongoDB® cluster with multiple nodes, called a replica set:

```
mongodb://<username>:<password>@<hostname node1>,<hostname node 2>,<hostname node 3>/admin?replicaSet=replicaset&tls=true
```

mongodbSrv

- It should be similar to this:

```
mongodb+srv://<username>:<password>@mongodb-xxxxxxxx-xxxxxxxxx.database.cloud.ovh.us/admin?replicaSet=replicaSet=replicaset&tls=true
```

**Note:**

**DNS Seed List Connection Format**

Introduced since MongoDB® 3.6, this new connection string URI format brings convenience and ease.

Instead of listing all the hosts one by one, MongoDB® introduced the concept of DNS-based lists. This method is recommended for drivers > 3.6.

Using DNS to construct the list of available servers allows more flexibility in deployment and the ability to modify the hosts without reconfiguring clients.

Without the SRV record, configuration clients must list several nodes in their connection string.

The use of SRV records eliminates the requirement for clients to pass in a complete set of state information for the cluster. Instead, a single SRV record identifies all the nodes associated with the cluster.

The DNS seed list connection string has the following format:

```bash
mongodb+srv://<username>:<password>@server.example.com/[/[defaultauthdb][?options]]
```

As an example, it may look like this with Public Cloud Databases, even with three nodes:

```bash
mongodb+srv://<username>:<password>@mongodb-d2a6c535-o099ad5c9.database.cloud.ovh.us/admin?replicaSet=replicaset&tls=true
```

The corresponding DNS configuration (SRV records) is specified at the instantiation of the MongoDB® service and might resemble:

```bash
Record                                                          TTL  Class    Priority Weight Port  Target
_mongodb._tcp.mongodb-d2a6c535-o099ad5c9.database.cloud.ovh.us. 1440 IN SRV   0        5      27017 node1-2d57ab70d2a6c535.database.cloud.ovh.us.
_mongodb._tcp.mongodb-d2a6c535-o099ad5c9.database.cloud.ovh.us. 1440 IN SRV   0        5      27017 node2-2d57ab70d2a6c535.database.cloud.ovh.us.
_mongodb._tcp.mongodb-708c0af6-o1b33fa01.database.cloud.ovh.us. 1440 IN SRV   0        5      27017 node3-2d57ab70d2a6c535.database.cloud.ovh.us.
```

Select the `Users` tab to get the username or reset a user password (_more_ _options_ `...`, then `Reset password`).

 

## Go further

Visit the [GitHub examples repository](https://github.com/ovh/public-cloud-databases-examples/tree/main/databases/mongodb) to find out how to connect to your database with several languages.

Browse all the [Databases guides](https://docs.us.ovhcloud.com/en/public-cloud/databases/landing-page-databases.md).

Browse the rest of the [OVHcloud US documentation](https://docs.us.ovhcloud.com/en/index.md) for guides on our other products and services.

Learn more about [Managed Databases](https://us.ovhcloud.com/public-cloud/databases/) on the OVHcloud US website.

If you need training or technical assistance to implement our solutions, contact your sales representative or click on [this link](https://us.ovhcloud.com/professional-services/) to get a quote and ask our Professional Services experts for a custom analysis of your project.

OVHcloud Managed Databases and Analytics:

- Grafana® is a registered trademark of Grafana Labs and is used with the permission of Grafana Labs. OVH SAS and its subsidiaries are not affiliated with or endorsed by Grafana Labs.
- Kafka® is a registered trademark of The Apache Software Foundation and has been licensed for use by OVHcloud, who has no affiliation with and is not endorsed by The Apache Software Foundation.
- MongoDB® is a registered trademark of MongoDB, Inc.
- MySQL® is a registered trademark of Oracle and/or its affiliates.
- PostgreSQL® is a registered trademark of the PostgreSQL Community Association of Canada.
