FAQ: Connection String Options
On this page
- Why does my cluster have multiple connection strings?
- What does this mean for Google Cloud or Azure clusters in peering-only mode?
- Can my VNet-peered Azure cluster span multiple regions?
- How do I disable peering-only mode?
- How does this affect AWS VPC peering when I use custom DNS?
- How do I identify which connection string my application uses?
- Do I have to update my connection string when migrating to a different cloud provider?
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 Google Cloud
- AWS peered clusters with a custom DNS service.
Use this connection string with applications connecting:
- Within an Azure or Google Cloud 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 Google Cloud 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 Google Cloud 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:
- Make sure your clusters use MongoDB 3.6 or later,
- Update your application's existing connection strings to use Private IP for Peering connection strings,
- Disable Peering-Only mode, and
- Connect using the strings outlined in Why does my cluster have multiple connection strings?.
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:
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:
- Toggle the Using Custom DNS on AWS with VPC Peering on
On
from the Project Settings menu. - View the connect modal for your AWS Cluster.
- 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.
This format changes one character from the
Legacy Connection Strings: a hyphen
(-
) after the cluster name becomes a period (.
).
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.
If you configure network peering for your cluster, you must use the
new hostname when you connect to your cluster to utilize the peering.
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.
AWS Privatelink Connection Strings
AWS PrivateLink connection strings follow this format:
mongodb://pl-0-us-east-1a.ab123.mongodb.net:1024 mongodb+srv://pl-0-us-east-1a.ab123.mongodb.net
If you enable the regionalized private endpoint setting, AWS PrivateLink connection strings follow this format:
mongodb://pl-0-us-west-1.ab123.mongodb.net:1024 mongodb+srv://cluster0-pl-0-us-west-1.ab123.mongodb.net
URIs using this format can be reachable via the AWS VPC where someone configured PrivateLink, though access can be transitive from other VPCs peered in turn.
Azure Private Link Connection Strings
Azure Private Link connection strings follow this format:
mongodb://pl-0-eastus2.ab123.azure.mongodb.net:1024 mongodb+srv://pl-0-eastus2.ab123.azure.mongodb.net
If you enable the regionalized private endpoint setting, Azure Private Link connection strings follow this format:
mongodb://pl-0-eastus2.ab123.azure.mongodb.net:1024 mongodb+srv://cluster0-pl-0-eastus2.ab123.azure.mongodb.net
URIs using this format can be reachable via the Azure VNet where someone configured Private Link, though access can be transitive from other VNets peered in turn.
Legacy Connection Strings
Before 31 March 2020, you wrote Atlas connection strings as follows:
AWS |
| ||
---|---|---|---|
Azure |
| ||
Google Cloud |
|
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 Google Cloud or Azure and was created before multi-cloud clusters were available:
- Open the cluster builder.
- Edit the cluster.
- Add read-only nodes from your target cloud provider.
- Review and submit the changes.
- Copy the resulting comma-delimited URI connection string.
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.
- Restart your application.
- Make sure that your application can connect to Atlas.
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.
- Review and submit the changes.
- Copy the resulting comma-delimited URI connection string.
- Replace the URI connection string in your application with this new URI connection string.
- Restart your application.
- Make sure that your application can connect to Atlas.
AWS
If your cluster runs on AWS or was created after October 2020:
- Open the cluster builder.
- Edit the cluster.
- Change the cloud provider.
- Review and submit the changes.