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, and this page is available as Markdown at https://docs.us.ovhcloud.com/en/public-cloud/databases/mongodb-configure-instance-accept-incoming-connections.md.
  • English

MongoDB® - Configure an instance to accept incoming connections

View as Markdown

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

 

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 and select your MongoDB® instance via the Public Cloud and Databases menus.

Manager - MongoDB configure instance accept incoming connections - step 3

 

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 to select the right roles for your use case.

Manager - MongoDB configure instance accept incoming connections

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.

Manager - MongoDB configure instance accept incoming connections - step 2

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.

Manager - MongoDB configure instance accept incoming connections - step 4

Info

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.

Manager - MongoDB configure instance accept incoming connections - step 5

Info

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.

 

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
Info

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:

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:

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:

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

Manager - MongoDB configure instance accept incoming connections - step 6

 

Go further

Visit the GitHub examples repository to find out how to connect to your database with several languages.

Browse all the Databases guides.

Browse the rest of the OVHcloud US documentation for guides on our other products and services.

Learn more about Managed 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 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.