MongoDB - Configure your MongoDB instance to accept incoming connections

Find out how to configure your MongoDB instance to accept incoming connections

Last updated 27th July 2022

Objective

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

This guide explains how to configure your MongoDB instance to accept incoming connections.

Requirements

Instructions

Configure your MongoDB instance to accept incoming connections

Before making a connection, we need to 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.

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 user called user with the roles readWriteAnyDatabase and userAdminAnyDatabase.

User Creation

Once created or updated, note the password then after a few seconds check to verify the user is ready and with the "Enabled" status in the OVHcloud Control Panel.

User ready

Step 2: Authorise incoming connections from the MongoDB client

In this step, select the Authorised IP's tab (Access Control List). By default, a Public Cloud Database does not accept any form of connection from the outside world. This way we can help prevent intrusive connection attempts.

Click to authorise a new IP. In our case we will enter 109.190.200.59:

Add an IP

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

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:

  • the Standard Connection String Format (service: mongodb).
  • the DNS Seed List Connection Format (service: mongodbSrv).

MongoDB General Information

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.

It should be similar to this when you have a single node (Essential service plan):

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

And like this when you have a MongoDB cluster with multiple nodes, called a replica set (Business or Enterprise service plans):

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

It should be similar to this:

mongodb+srv://<username>:<password>@mongodb-d5674315-o2626ab53.database.cloud.ovh.net/admin?replicaSet=replicaset

Select the Users tab to get the username or reset a user password.

Users tab

Go further

MongoDB capabilities

Visit our dedicated Discord channel: https://discord.gg/PwPqWUpN8G. Ask questions, provide feedback and interact directly with the team that builds our databases services.

Join our community of users on https://community.ovh.com/en/.


Haben Ihnen die Anleitungen geholfen?

Bevor Sie Ihre Meinung abgeben, nehmen wir gerne Ihre Vorschläge auf, wie wir diese Dokumente verbessern können.

Woran liegt es? An den Bildern, dem Inhalt oder Aufbau der Anleitungen? Schreiben Sie es uns gerne, dann machen wir es zusammen besser.

Ihre Support-Anfragen werden in diesem Formular nicht entgegengenommen. Verwenden Sie hierfür bitte das Formular "Ein Ticket erstellen" .

Vielen Dank. Ihr Feedback wurde gesendet.


Diese Anleitungen könnten Sie auch interessieren...

OVHcloud Community

Besuchen Sie Ihren Community-Bereich und tauschen Sie sich mit anderen Mitgliedern der OVHcloud Community aus. Hier können Sie Fragen stellen, zusätzliche Informationen finden und eigene Inhalte veröffentlichen.

Tauschen Sie sich mit der Community aus

Alle Preise verstehen sich inklusive der gesetzlichen Mehrwertsteuer.

In Übereinstimmung mit der Richtlinie 2006/112/EG in der geänderten Fassung können die Preise ab 01.01.2015 je nach Wohnsitzland des Kunden variieren
(die Preise in den Angeboten verstehen sich inklusive der gesetzlichen Mehrwertsteuer für die Bundesrepublik Deutschland).