Learn how to configure your MongoDB instance to accept incoming connections.
Managed Databases (also called 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 in your OVHcloud account
- access to the OVHcloud Control Panel
- a MongoDB database running on your OVHcloud Cloud Databases (this guide 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 and open your Public Cloud
project. Click on Databases
in the left-hand navigation bar and select your MongoDB instance.
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.
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 →
.
Once created or updated, note the password. After a few seconds, check to verify the user is ready and with the "Enabled" status in the OVHcloud Control Panel.
Step 2: Authorize incoming connections from the MongoDB client
In this step, select the Authorised IPs
tab and click + Add an IP address or IP block (CIDR)
. 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.
Enter the IP address or block you want to authorize (for example, 109.190.200.59) and click Confirm
to authorize a new IP.
Get your connection information (URI)
Select the General Information
tab. In the Login 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.
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:
- And like this when you have a MongoDB cluster with multiple nodes, called a replica set:
mongodbSrv
- It should be similar to this:
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:
As an example, it may look like this with Public Cloud Databases, even with three nodes:
The corresponding DNS configuration (SRV records) is specified at the instantiation of the MongoDB service and might resemble:
Select the Users
tab to get the username or reset a user password (more options ...
, then Reset the password
).
Go further
Visit the GitHub examples repository to find out how to connect to your database with several languages.
For more information and tutorials, please see our other MongoDB and Cloud Databases support guides or explore the guides for other OVHcloud products and services.
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.