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

# Connect Two Atlas Clusters

The [mongosync](https://www.mongodb.com/docs/mongosync/current/reference/mongosync-binary.md#std-label-c2c-mongosync) utility creates a connection between MongoDB clusters. `mongosync` can connect to any of the following clusters:

- [self-managed clusters](https://www.mongodb.com/docs/manual/administration/replica-set-deployment.md#std-label-server-replica-set-deploy-all)

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas/) hosted clusters

- a self-managed cluster and an Atlas hosted cluster

This page provides instructions to connect Atlas clusters using MongoDB Mongosync. For additional details on connecting to an Atlas cluster, see [Connect to a Database Deployment](https://www.mongodb.com/docs/atlas/connect-to-database-deployment.md#std-label-atlas-connect-to-deployment)

## Considerations

- Both the source and destination Atlas clusters must use MongoDB 6.0 or later.

- `mongosync` supports replica sets and sharded clusters.

- `mongosync` **doesn't** support Atlas shared clusters or serverless instances. You can use `mongosync` only with M10 or higher Atlas clusters.

  **Important:**

  Do not choose Latest Version With Auto Upgrades. This option auto upgrades your cluster to the latest minor release. Some minor releases, such as MongoDB version 8.2, may not support Live Migration or Mongosync. When [upgrading](https://www.mongodb.com/docs/atlas/tutorial/major-version-change.md#std-label-upgrade-major-MongoDB-version), choose a major version to ensure compatibility with Live Migration and Mongosync.

## Connection Strings

`mongosync` uses a [MongoDB URI connection string](https://www.mongodb.com/docs/manual/reference/connection-string.md#std-label-mongodb-uri) to connect Atlas clusters:

- The SRV connection scheme has the form:

  ```text
  mongodb+srv://[username:password]@[clusterName].[host].mongodb.net/

  ```

  For information on how to find your SRV connection string in Atlas, see [Connect to Your Cluster.](https://www.mongodb.com/docs/atlas/tutorial/connect-to-your-cluster/)

- The standard URI connection scheme has the form:

  ```text
  mongodb://[username:password]@[clusterName].[host].mongodb.net/

  ```

`mongosync` requires the [`primary`](https://www.mongodb.com/docs/manual/core/read-preference.md#mongodb-readmode-primary) read preference to connect to the source and destination clusters. For more information, see [Read Preference Options.](https://www.mongodb.com/docs/manual/reference/connection-string-options.md#std-label-connections-read-preference)

## Authentication

Provide valid authentication to connect to a [MongoDB Atlas](https://www.mongodb.com/docs/atlas/) cluster. If you do not already have an Atlas database user, you must [create a user.](https://www.mongodb.com/docs/atlas/security-add-mongodb-users.md#std-label-mongodb-users)

## 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 use reverse sync.

The Atlas permissions are:

| Sync Type | Required Source Permissions | Required Destination Permissions |
| --- | --- | --- |
| Default | atlasAdmin | atlasAdmin; [`bypassWriteBlockingMode`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-bypassWriteBlockingMode) |
| Reversing or multiple reversals | atlasAdmin; [`bypassWriteBlockingMode`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-bypassWriteBlockingMode) | atlasAdmin; [`bypassWriteBlockingMode`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-bypassWriteBlockingMode) |

For details on Atlas roles, see [Atlas User Roles.](https://www.mongodb.com/docs/atlas/reference/user-roles.md#std-label-user-roles)

To update Atlas user permissions, see: [Manage Access to a Project.](https://www.mongodb.com/docs/atlas/access/manage-project-access/)

## 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`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances in the cluster. This flexibility allows you to push, or pull, data to the destination cluster with minimal impact on the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances running there.

### Initial State

When `mongosync` connects, it is in the `IDLE` state. You must issue the [start](https://www.mongodb.com/docs/mongosync/current/reference/api/start.md#std-label-c2c-api-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 to set [`notablescan`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.notablescan) to `false` on both the source and destination clusters.

## Example

### Gather Connection Information

The generic connection string format is:

```shell
mongodb://<user>:<password>@<clusterName>.<hostname>.mongodb.net/

```

You can get the connection string for the Atlas clusters from the Atlas UI. To learn more, see [Connect to a Database Deployment.](https://www.mongodb.com/docs/atlas/connect-to-database-deployment/)

The connection strings you gathered for `cluster0` and `cluster1` should resemble the following:

```shell
cluster0:
mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net
cluster1:
mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net

```

There is an database administrative user `clusterAdmin` with the password `superSecret` in the project that contains the clusters.

### Connect the Source and Destination Clusters with `mongosync`

The `mongosync` command layout below is modified for display. To connect `cluster0` to `cluster1` with `mongosync`, enter the following command on one line:

```shell
mongosync \
      --cluster0 "mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net" \
      --cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net"

```

Atlas clusters require TLS connections. To use `mongosync` with Atlas clusters, you add the [`tls=true`](https://www.mongodb.com/docs/manual/reference/connection-string-options.md#mongodb-urioption-urioption.tls) option. For example, to connect to the `admin` database on `cluster0` and `cluster1`:

```shell
mongosync \
   --cluster0 "mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net/admin?tls=true" \
   --cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/admin?tls=true"

```

You can also use `mongodb+srv` connection strings with `mongosync`. You do not need to add the [`tls=true`](https://www.mongodb.com/docs/manual/reference/connection-string-options.md#mongodb-urioption-urioption.tls) option to a `mongodb+srv` connection string. For example:

```shell
mongosync \
   --cluster0 "mongodb+srv://clusterAdmin:superSecret@cluster1Name.abc123.mongodb.net/" \
   --cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/"

```

For more details about `mongodb+srv` connection strings, see [SRV Connection Format.](https://www.mongodb.com/docs/manual/reference/connection-string-formats.md#std-label-connections-dns-seedlist)
