Navigation
  • FAQ >
  • Connection String Options

Connection String Options

Atlas provides multiple connection strings. These strings allow you to connect to your clusters from both public and private contexts.

Why does my cluster have multiple connection strings?

To connect to Atlas, point your applications to a URI to communicate with a cluster. Atlas creates clusters with more than one node or host. Each node has its own hostname that resolves to an IP address. The URI, known as a connection string, to which Atlas connects might have more than one hostname. Configure Atlas to accept connections to the cluster hosts from allowed IP addresses.

Atlas secures connections from public IP address through authentication and TLS. If you want to connect to private IP addresses, you can use:

These features all manage communication over internal IP addresses within secure networks.

Atlas provides more than one connection string when using secure networks. Each network offers a string that resolves to different IP addresses.

All clusters have a standard connection string. This resolves to the cluster’s:

  • Public IP addresses for Internet connections and
  • VPC private IP addresses for AWS clusters when resolved from a peered VPC.

Use this string for applications connecting over the Internet or connecting to peered clusters in AWS.

Clusters with peered networks have a Private IP for Peering connection string. This string resolves to IP addresses available to:

  • Peered networks in Azure or GCP
  • AWS peered clusters with a custom DNS service.

Use this connection string with applications connecting:

  • Within an Azure or GCP peered network
  • To AWS clusters when using AWS with custom DNS service.

AWS or Azure clusters in regions with private endpoints configured have one or more connection strings. Each string resolves to the private IP address of a network interface in your VPC or VNet that connects directly to a load balancer in the Atlas VPC or VNet. Use these connection strings with applications connecting with private endpoints.

What does this mean for GCP or Azure clusters in peering-only mode?

Before 31 March 2020, you were required to enable peering-only mode to connect to databases on peer networked Azure or GCP clusters. This mode:

  • Affected global DNS resolution and
  • Limited any database connections outside the peered network.

Multiple horizons lifts these restrictions and unlocks additional features. In projects running MongoDB 3.6 or later clusters, you can use:

To leverage multiple horizons:

Note

You can keep connecting to your clusters using existing peering-enabled connection strings at this time. Peering-Only mode prevents access to the improved functionality and reduced limitations of multiple horizons. To use the new features and remove the legacy limitations, MongoDB requires that you use the new connection strings.

Can my VNet-peered Azure cluster span multiple regions?

Yes.

Change your applications to connect using the Private IP for Peering connection string. This change allows your applications to connect from peered networks using the UI or API.

To expand into more regions, disable Peering-Only mode on existing Azure clusters first.

Private IP for Peering connection strings work with MongoDB 3.6 or later clusters.

How do I disable peering-only mode?

To disable Peering-Only mode using the:

1

Verify all clusters in your project use MongoDB 3.6 or later.

  1. If it is not already displayed, select the organization that contains your desired project from the office icon Organizations menu in the navigation bar.
  2. If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
  3. If the Clusters page is not already displayed, click Clusters in the sidebar.
  4. Check the Version number under the cluster name in each cluster card on the Clusters page.

For each cluster that doesn’t run MongoDB 3.6 or later, upgrade the MongoDB version of that cluster.

2

Update All Applications to Use Private IP for Peering Connection Strings.

Change any URLs in your applications that use your Atlas clusters to use Private IP for Peering connection strings.

3
4

Disable Connect via Peering Only.

Toggle Connect via Peering Only (GCP and Azure) to Off.

1

Verify all clusters in your project use MongoDB 3.6 or later.

Call the Get All Clusters API endpoint to return all clusters and their MongoDB versions:

Example

curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \
     --header "Accept: application/json" \
     --header "Content-Type: application/json" \
     --include \
     --request GET "https://cloud.mongodb.com/api/atlas/v1.0/groups/{PROJECT-ID}/clusters?pretty=true"

If successful, the response should include:

{
  "results": [{
    ...
    "mongoDBMajorVersion": "4.2",
    "mongoDBVersion": "4.2.3",
    ...
  },{
    ...
    "mongoDBMajorVersion": "4.0",
    "mongoDBVersion": "4.0.14",
    ...       }
  ]
}

If all clusters return a "mongoDBMajorVersion" value of 3.6 or greater, you can continue. If need to upgrade, follow the Upgrade Major MongoDB Version for a Cluster procedure or call the Modify a Cluster endpoint to upgrade.

2

Update All Applications to Use Private IP for Peering Connection Strings.

Change any URLs in your applications that use your Atlas clusters to use Private IP for Peering connection strings.

3

Disable Private IP Mode on Your Clusters.

Call the API endpoint to Disable Private IP Mode.

Example

Using curl, you would invoke this command:

curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \
     --header "Accept: application/json" \
     --header "Content-Type: application/json" \
     --include \
     --request PATCH "https://cloud.mongodb.com/api/atlas/v1.0/groups/{PROJECT-ID}/privateIpMode?pretty=true" \
     --data '
       {
         "enabled" : false
       }'

Change {PROJECT-ID} to the Project ID of your project.

If successful, the response displays:

1
2
3
{
  "enabled" : false
}

How does this affect AWS VPC peering when I use custom DNS?

Before 31 March 2020, applications deployed within AWS using custom DNS services and VPC-peered with Atlas couldn’t connect over private IP addresses:

  • Custom DNS resolved to public IP addresses.
  • AWS internal DNS resolved to private IP addresses.

Applications deployed with custom DNS services in AWS should use Private IP for Peering connection strings. To show these strings:

  1. Toggle the Using Custom DNS on AWS with VPC Peering on On from the Project Settings menu.
  2. View the connect modal for your AWS Cluster.
  3. Select the Private IP for Peering connection string.

How do I identify which connection string my application uses?

The structure of the connection string’s URI indicates the string’s type. If you have created a peering connection or private endpoint, Atlas displays more than one of these options for your use.

Standard Connection Strings

Standard connection strings follow this format:

mongodb://xyz456-shard-00-00.ab123.mongodb.net:27017
mongodb+srv://xyz456.ab123.mongodb.net

The dot before ab123 matters. URIs using this format resolve to public IP addresses except when connecting from inside AWS with VPC-peering configured.

Important

This format changes one character from the Legacy Connection Strings: a hyphen (-) after the cluster name becomes a period (.).

Example

This legacy connection string:

mongodb+srv://xyx456-ab123.mongodb.net

is written as this standard connection string:

mongodb+srv://xyx456.ab123.mongodb.net

For new clusters, replica sets and shards don’t derive their name from the name of the cluster. The new names use a six alphanumeric character ID.

Private Connection Strings

Private connection strings follow this format:

mongodb://xyx456-shard-00-00-pri.ab123.mongodb.net:27017
mongodb+srv://xyx456-pri.ab123.mongodb.net

The -pri before ab123 matters. URIs using this format resolve to private IP addresses reachable within the peered network.

Important

In new clusters, replica sets and shards don’t derive their name from the name of the cluster. The new names use a six alphanumeric character ID.

Legacy Connection Strings

Before 31 March 2020, you wrote Atlas connection strings as follows:

AWS
foo-shard-00-00-ab123.mongodb.net
foo-ab123.mongodb.net
Azure
foo-shard-00-00-ab123.azure.mongodb.net
foo-ab123.azure.mongodb.net
GCP
foo-shard-00-00-ab123.gcp.mongodb.net
foo-ab123.gcp.mongodb.net

If you enabled Private Only mode, these hostnames resolve to peered network IP addresses. If you disabled that mode, hostnames resolve to public IP addresses.

If your application uses a legacy connection string in Peering Only mode, switch to Private IP for Peering connection strings.

Do I have to update my connection string when migrating to a different cloud provider?

It depends on:

  • which cloud provider your current cluster uses and
  • when you created the cluster.

GCP or Azure

If your cluster runs on GCP or Azure and was created before multi-cloud clusters were available:

  1. Open the cluster builder.

  2. Edit the cluster.

  3. Add read-only nodes from your target cloud provider.

  4. Review and submit the changes.

  5. Copy the resulting comma-delimited URI connection string.

  6. Replace the connection string in your application with this new standard connection string.

    This allows your application to connect to nodes from multiple cloud providers.

    Note

    Atlas doesn’t support SRV connection strings for multi-cloud clusters at this time.

  7. Restart your application.

  8. Make sure that your application can connect to Atlas.

  9. After the first change completes, reconfigure your cluster:

    • Remove all electable nodes using the original cloud provider.
    • Remove the read-only nodes for the target cloud provider.
    • Add the same number of electable nodes using the target cloud provider.
  10. Review and submit the changes.

  11. Copy the resulting comma-delimited URI connection string.

  12. Replace the URI connection string in your application with this new URI connection string.

  13. Restart your application.

  14. Make sure that your application can connect to Atlas.

AWS

If your cluster runs on AWS or was created after October 2020:

  1. Open the cluster builder.
  2. Edit the cluster.
  3. Change the cloud provider.
  4. Review and submit the changes.
←   Billing Database  →