> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  drivers: c, cpp, csharp, go, java-sync, kotlin-coroutine, nodejs, php, python, ruby, rust-async, rust-sync, scala, swift-async, swift-sync
  other tabs: standard, peering, private
-->

# Connect to a Cluster via Client Libraries

The Connect dialog box for a cluster provides the details to connect to a cluster with an application using a [MongoDB client library.](https://www.mongodb.com/docs/drivers/)

***

➤ Use the **Select your language** drop-down menu to set the language of the example on this page.

***

## Prerequisites

### Node.js

### 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 [Client Library Compatibility Table](https://www.mongodb.com/docs/drivers/compatibility/) for your driver.

**Important: Officially Supported Drivers**

Use [officially supported MongoDB drivers](https://www.mongodb.com/docs/drivers/) at current versions for the best reliability and support experience. The Atlas SLA covers officially supported drivers only.

Atlas provides best-effort, diagnosis-only support for community drivers and end-of-life driver versions. Atlas does not test, patch, or certify community drivers. Support helps you determine whether connection issues originate from the platform or the driver, but does not debug driver code.

To learn more, see [What is Atlas's support policy for community and unsupported drivers?.](https://www.mongodb.com/docs/atlas/reference/faq/security.md#std-label-faq-community-driver-support)

### Optimized Connection Strings for Sharded Clusters Behind a Private Endpoint

You can connect to your sharded cluster using a driver and an [optimized connection string.](https://www.mongodb.com/docs/atlas/reference/faq/connection-changes.md#std-label-optimized-connection-strings)

### TLS (Transport Layer Security)

Clients must support TLS (Transport Layer Security) to connect to an Atlas cluster.

Clients must support the [SNI](https://tools.ietf.org/html/6066#section-3) TLS (Transport Layer Security) extension to connect to an Atlas Free cluster (formerly known as `M0`) or Flex cluster.

#### IP Access List

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 box. You can also add the IP address from the [Network Access tab.](https://www.mongodb.com/docs/atlas/security/ip-access-list.md#std-label-add-to-access-list)

#### Database User

To access a cluster, you must have a [database user](https://www.mongodb.com/docs/manual/core/security-users/) with access to the desired databases 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 your Atlas cluster in the Connect dialog box. You can also add the database user from the [Cluster view](https://www.mongodb.com/docs/atlas/security-add-mongodb-users.md#std-label-mongodb-users). Atlas creates a database user when you create your first cluster.

## Connect Your Application

1. In Atlas, go to the Clusters page for your project.

   If it's not already displayed, select the organization that contains your desired project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

   In the sidebar, click Clusters under the Database heading.

   The [Clusters](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters) page displays.

2. Click Connect.

   Click Connect for the cluster to which you want to connect.

3. Choose your Connection Security.

   Choose Connection Type from the set of available buttons.

   **Note: Options Display if Feature Enabled**

   Atlas displays the connection type options after you enable [Private IP for Peering](https://www.mongodb.com/docs/atlas/security-vpc-peering.md#std-label-vpc-peering), [Private Endpoint](https://www.mongodb.com/docs/atlas/security-configure-private-endpoints.md#std-label-atlas-configure-private-endpoint), or both. If you haven't enabled either feature, no buttons display and **Connection Type** defaults to **Standard**.

   ### Standard Connection

   Use this connection type for allowed public IP addresses.

4. Choose how you want to limit connections to your cluster.

   ### Standard Connection

   Add a Connection IP Address

   **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.](https://www.mongodb.com/docs/atlas/security/ip-access-list.md#std-label-access-list)

   Atlas allows standard client connections to the cluster from entries in the [project's IP access list](https://www.mongodb.com/docs/atlas/security/ip-access-list.md#std-label-access-list). The project IP access list differs from the [API access list](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-enable-api-access-list), which restricts *API* access to specific IP or CIDR (Classless Inter-Domain Routing) 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 (Classless Inter-Domain Routing)-notated range of addresses.

   Provide an optional description for the newly added IP address or CIDR (Classless Inter-Domain Routing) range. Click Add IP Address to add the address to the IP access list.

5. Create a Database User.

   **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.](https://www.mongodb.com/docs/atlas/security-add-mongodb-users.md#std-label-mongodb-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](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#std-label-atlas-user-privileges) 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 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.

6. Select Drivers.

   In the Choose a connection method step, select Drivers.

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

   Under Use this connection string in your application, the connection string uses the SRV (DNS Service Record) format (`mongodb+srv://`) by default. To view the standard (non-SRV) connection string (`mongodb://`), turn off the SRV Connection String toggle.

   **Note:**

   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.](https://www.mongodb.com/docs/atlas/troubleshoot-connection.md#std-label-special-pass-characters)

   To learn more, see [Driver Compatibility.](https://www.mongodb.com/docs/drivers/about-compatibility/)

## Driver Examples

In the following example, you authenticate and connect to an Atlas cluster by using a [URI connection string](https://www.mongodb.com/docs/manual/reference/connection-string/). Replace the placeholders in the example with your credentials and deployment details.

### Node.js

**Note:**

To connect to an Atlas `M0` Free cluster or a Flex cluster, you must use a Node.js driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the Node.js driver and MongoDB, see the [MongoDB compatibility matrix](https://www.mongodb.com/docs/drivers/node/current/compatibility/). We recommend that you upgrade to the latest version of the driver.

```javascript
import mongodb from 'mongodb';

const MongoClient = mongodb.MongoClient;
const uri = "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri);
client.connect(err => {
  const collection = client.db("<databaseName>").collection("<collectionName>");
  // perform actions on the collection object
  client.close();
});
```

To connect to a database other than `admin` but still authenticate to the `admin` database, update the `database` component of the connection string.

```sh
mongodb://username:password@host1:port1,...,hostN:portN/database?authSource=admin&...
```

**Example:**

The following connection string specifies the `cluster0` deployment and `test` database component, and includes the `authSource=admin` option.

```javascript
var uriTestDb = "mongodb+srv://<db_username>:<db_password>@cluster0.mongodb.net/test?ssl=true&authSource=admin&w=majority";
MongoClient.connect(uriTestDb, function(err, db) {
   db.close();
});
```

| MongoDB Version | Recommended Driver Versions |
| --- | --- |
| All | See the [MongoDB compatibility matrix](https://www.mongodb.com/docs/drivers/node/current/compatibility/) for the latest recommended driver versions. |
| MongoDB 7.0 and later | Version 3.1 and later |

## Troubleshooting

If you are experiencing issues connecting to your cluster, see [Troubleshoot Connection Issues.](https://www.mongodb.com/docs/atlas/troubleshoot-connection.md#std-label-atlas-troubleshoot-connections)

**See also:**

[Connection Limits and Cluster Tier](https://www.mongodb.com/docs/atlas/reference/atlas-limits.md#std-label-connection-limits)
