Connect Two Atlas Clusters
The mongosync utility creates a connection
between MongoDB clusters. mongosync
can make a connection between:
MongoDB Atlas hosted clusters, or
a self-managed cluster and an Atlas hosted cluster.
This page provides instructions to connect Atlas clusters using MongoDB Cluster-to-Cluster Sync. For additional details on connecting to an Atlas cluster, see Connect to a Database Deployment
Connection Strings
mongosync
uses a MongoDB URI
connection string to connect Atlas clusters:
The SRV connection scheme has the form:
mongodb+srv://[username:password@][host.domain.TLD][:port][/defaultauthdb][?options] For information on how to find your SRV connection string in Atlas, see Connect to Your Cluster.
The standard URI connection scheme has the form:
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
Specify the hostnames of the mongod
instances the same way
that they are listed in your replica set configuration.
For sharded clusters, specify the
hostnames of the mongos
instances instead of the
mongod
instances.
Note
mongosync
does not require the replicaSet
option.
mongosync
requires the primary
read preference to
connect to the source and destination clusters. For more information,
see Read Preference Options.
Authentication
Provide valid authentication to connect to a MongoDB Atlas cluster. If you do not already have an Atlas database user, you must create a user.
Roles
The user specified in the mongosync
connection string must have the
required permissions on the source and destination clusters. The
permissions vary depending on your environment and if you want to run a
write-blocking or reverse sync.
The Atlas permissions are:
Sync Type | Target | Required Permissions |
---|---|---|
default | source cluster |
|
default | destination cluster |
|
write-blocking or reversing | source cluster |
|
write-blocking or reversing | destination cluster |
|
For details on Atlas roles, see: Atlas User Roles.
To update Atlas user permissions, see: Manage Access to a Project.
Behavior
Hosting
The mongosync
utility can be hosted on its own hardware close to
either the source or destination cluster. It does not have to be hosted
on the same server as one of the mongod
or mongos
instances in the cluster. This flexibility allows you to push, or pull,
data to the destination cluster with minimal impact on the
mongod
or mongos
instances running there.
Initial State
When mongosync
connects, it is in the IDLE
state. You must
issue the start command to begin syncing.
Limitations
Before you attempt to run mongosync
with an M10+
Atlas cluster, disable
the Require Indexes for All Queries option.
Example
Gather Connection Information
The source cluster, cluster0
, is hosted on the following servers
and ports:
clusterOne-shard-00-00.abc12.mongodb.net:27017
clusterOne-shard-00-01.abc12.mongodb.net:27017
clusterOne-shard-00-02.abc12.mongodb.net:27017
The destination cluster, cluster1
, is hosted on the following
servers and ports:
clusterTwo-shard-00-00.abc12.mongodb.net:27017
clusterTwo-shard-00-01.abc12.mongodb.net:27017
clusterTwo-shard-00-02.abc12.mongodb.net:27017
There is an administrative user, clusterAdmin
configured on each
cluster with password, superSecret
.
Connect the Source and Destination Clusters with mongosync
Use the connection information you gathered to create the connection
strings for cluster0
and cluster1
:
cluster0: mongodb+srv://clusterAdmin:superSecret@clusterOne.abc12.mongodb.net cluster1: mongodb+srv://clusterAdmin:superSecret@clusterTwo.abc12.mongodb.net
Note
Atlas clusters require TLS connections. To use mongosync
with Atlas
clusters, add the tls=true
option or use the
mongodb+srv
connection string format. For more details about
mongodb+srv
connection strings, see SRV Connection Format.
The mongosync
command layout below is modified for display. To
connect cluster0
to cluster1
with mongosync
, enter the
following command on one line:
mongosync \ --cluster0 "mongodb+srv://clusterAdmin:superSecret@clusterOne.abc12.mongodb.net" \ --cluster1 "mongodb+srv://clusterAdmin:superSecret@clusterTwo.abc12.mongodb.net"