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 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 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 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.
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.
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:
- 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 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 Managed Databases & Analytics or Platform as a Service guides. You can also 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.
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.