Navigation

Connect via Driver

The Connect dialog for a cluster provides the details to connect to a cluster with an application using a MongoDB driver.

Bulb IconTip
See Also:

Your driver version must be compatible with your version of the MongoDB server. We recommend choosing the latest driver that is compatible with your MongoDB server version to utilize the latest database features and prepare for future version upgrades.

For a list of driver versions that contain the full set of functionality for your version of the MongoDB server, check the compatibility matrix for your MongoDB driver.

Important With Circle IconCreated with Sketch.Important

When you upgrade your driver version, some commands, methods or options may be deprecated and removed. Check your MongoDB driver API documentation to ensure a smooth transition.

Info With Circle IconCreated with Sketch.Note
3.6-Series Driver Compatibility with MongoDB 4.2

The drivers recommended for MongoDB 3.6 in the driver compatibility matrices are tested against MongoDB 4.2. Check the MongoDB driver documentation page for the driver compatibility matrix for your language.

Applications running with 3.6-series drivers will work against MongoDB clusters running MongoDB 4.2 as long as:

We still recommend using MongoDB 4.2-series drivers with MongoDB 4.2 to utilize newer database features and better prepare for future version upgrades.

Clients must support TLS to connect to an Atlas cluster.

Clients must support the SNI TLS extension to connect to an Atlas M0 Free Tier or M2/M5 shared starter cluster. To verify that your MongoDB driver supports the SNI TLS extension, refer to the Compatibility section of your driver's documentation. If the driver is compatible with MongoDB 3.4 and later, it supports the SNI TLS extension.

To access a cluster, you must connect from an IP address on the Atlas project's IP access list. If you need to add an IP address to the IP access list, you can do so in the Connect dialog. You can also add the IP address from the Network Access tab.

To access a cluster, you must create a database user with access to the desired database(s) on your Atlas cluster. Database users are separate from Atlas users. Database users have access to MongoDB databases, while Atlas users have access to the Atlas application itself.

You can create a database user to access to your Atlas cluster in the Connect dialog. You can also add the database user from the Clusters view.

1

In the Clusters view, click Connect for the cluster to which you want to connect.

2

Choose Connection Type from the set of available buttons.

Info With Circle IconCreated with Sketch.Note
Options Display if Feature Enabled

Atlas displays the connection type options after you enable Private IP for Peering, Private Endpoint, or both. If you haven't enabled either feature, no buttons display and Connection Type defaults to Standard.

Use this connection type for allowed public IP addresses.

3

Add a Connection IP Address

Important With Circle IconCreated with Sketch.Important

Skip this step if Atlas indicates in the Setup connection security step that you have already configured an IP access list entry in your cluster. To manage the IP access list, see Add Entries to the Access List.

Atlas allows standard client connections to the cluster from entries in the project's IP access list. The project IP access list differs from the API access list, which restricts API access to specific IP or CIDR addresses.

If the IP access list is empty, Atlas prompts you to add an IP address to the project's IP access list. You can either:

  • Click Add Your Current IP Address to allow access from your current IP address.
  • Click Add an IP Address to add a single IP address or a CIDR -notated range of addresses.

Provide an optional description for the newly added IP address or CIDR range. Click Add IP Address to add the address to the IP access list.

4
Important With Circle IconCreated with Sketch.Important

Skip this step if Atlas indicates in the Setup connection security step that you have at least one database user configured in your project. To manage existing database users, see Configure Database Users.

To access the cluster, you need a MongoDB user with access to the desired database or databases on the cluster in your project. If your project has no MongoDB users, Atlas prompts you to create a new user with the Atlas Admin role.

  1. Enter the new user's Username
  2. Enter a Password for this new user or click Autogenerate Secure Password.
  3. Click Create Database User to save the user.

Use this user to connect to your cluster in the following step.

Once you have added an IP address to your IP access list and added a database user, click Choose Your Connection Method.

5

In the Choose a connection method step, select Connect your application.

6
  1. Select your driver and version from the dropdown menus.
  2. The Connection String Only tab displays the connection string you can use to connect to your Atlas cluster. The Full Driver Example tab displays a code sample for your selected driver and version demonstrating a connection to your Atlas cluster.

    Info With Circle IconCreated with Sketch.Note

    The connection string displayed in the console uses a placeholder value for the password. Replace that placeholder with the password specified when you created your database user.

    If the password contains reserved URI characters, you must escape the characters. For example, if your password is @bc123, you must escape the @ character when specifying the password in the connection string, such as %40bc123. To learn more, see Special characters in connection string password.

To learn more, see Driver Compatibility.

The connection string examples specify the test database for the initial connection. If you configured the user on a different database, specify that database in the connection string.

In this example URI connection strings, the user kay provides their password myRealPassword to authenticate and connect to an Atlas cluster.

Select your driver from the following options:

Info With Circle IconCreated with Sketch.Note

To connect to an Atlas M0 (Free Tier) cluster, you must use Python 2.7.9+ and use a Python driver version that supports MongoDB 3.6. For complete documentation on compatibility between the Python driver and MongoDB, see the MongoDB compatibility matrix.

import pymongo
import dns # required for connecting with SRV
client = pymongo.MongoClient("mongodb+srv://kay:myRealPassword@cluster0.mongodb.net/test?w=majority")
db = client.test
MongoDB VersionRecommended Driver Version(s)
AllSee the MongoDB compatibility matrix for the latest recommended driver versions.
MongoDB 4.0Version 3.7 or later.
MongoDB 3.6Version 3.6 or later.
Info With Circle IconCreated with Sketch.Note
macOS and Python 3.6 Installers

The Python 3.6 installers for macOS from https://www.python.org do not automatically install any CA certificates. Without installed CA certificates, connections to Atlas will fail certificate verification.

After you run the installer from https://www.python.org to install Python 3.6, you must run the following script to install an up-to-date CA bundle before connecting to Atlas:

open "/Applications/Python 3.6/Install Certificates.command"

For more information on Python 3.6 installers for macOS from https://www.python.org, see https://bugs.python.org/issue29065#msg283984. Earlier versions of Python as well as Python 3.6 installed by other means (e.g. Homebrew), are not affected.

If you are experiencing issues connecting to your cluster, see Troubleshoot Connection Issues.

Give Feedback

Select your language