Connect via Your Application
The Connect dialog for a database deployment provides the details to connect to a database deployment with an application using a MongoDB driver.
Serverless instances are in preview and do not support connecting via certain drivers or driver versions at this time. To learn more, see Serverless Instance Limitations.
Prerequisites
Driver Version
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 use 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.
For a list of driver versions that you can use to connect to serverless instances, see Minimum Driver Versions for Serverless Instances.
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.
Applications running with 4.0-series drivers will work with MongoDB database deployments running MongoDB 4.4 as long as:
- The drivers recommended for MongoDB 3.6 in the driver compatibility matrices are tested against MongoDB 4.4. Check the MongoDB driver documentation page for the driver compatibility matrix for your language.
- No functionality new to MongoDB 4.0, MongoDB 4.2, or MongoDB 4.4 is being used, and
- No commands, methods, or options removed in
MongoDB 4.0,
MongoDB 4.2
(including
db.collection.geoNear()
,db.collection.group()
, anddb.eval()
), or MongoDB 4.4 are being used, and - Other compatibility changes in
MongoDB 4.4 to
projections
(including$slice projections
),$sort
,text search
, andmapReduce
do not impact them.
We recommend using MongoDB 4.4-series drivers with MongoDB 4.4 to use newer database features and prepare for future version upgrades.
TLS
Clients must support TLS to connect to an Atlas database deployment.
Clients must support the SNI TLS extension to
connect to an Atlas M0
free cluster or M2/M5
shared 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 4.0
and later, it supports the SNI TLS extension.
IP Access List
To access a database deployment, 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.
Database User
To access a database deployment, you must create a database user with access to the desired database(s) on your Atlas database deployment. 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 your Atlas database deployment in the Connect dialog. You can also add the database user from the Database Deployment view.
Connect Your Application
Choose your Connection Security.
Choose Connection Type from the set of available buttons.
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.
Create a Database User.
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 database deployment, you need a MongoDB user with access to the desired database or databases on the database deployment in your project. If your project has no MongoDB users, Atlas prompts you to create a new user with the Atlas Admin role.
- Enter the new user's Username.
- Enter a Password for this new user or click Autogenerate Secure Password.
- Click Create Database User to save the user.
Use this user to connect to your database deployment 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.
Select Your Driver and Version.
Select your driver and version from the dropdown menus. The code sample containing a connection string displays.
- Replace
<password>
with the password specified when you created your database user. - Replace
<myFirstDatabase>
with the name of the database that connections will use by default. If you omit the database, thetest
database is used by default. If you configured the user on a different database, specify that database in the connection string.
If your passwords, database names, or connection strings contain
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.
Driver Examples
In this example
URI connection strings, the
user kay
provides their password myRealPassword
to
authenticate and connect to an Atlas database deployment.
Select your driver from the following options:
Troubleshooting
If you are experiencing issues connecting to your database deployment, see Troubleshoot Connection Issues.