Sync a Replica Set to a Sharded Cluster
This page outlines the procedure to synchronize data from a replica set to a
sharded cluster using mongosync
.
Note
mongosync
doesn't support syncing from a sharded cluster to a replica
set.
Before You Begin
Define your source replica set and destination sharded cluster.
Define an administrative user that has permissions in both clusters.
Download and install
mongosync
.
To learn more, see the mongosync setup instructions.
Steps
Connect the replica set and sharded cluster
mongosync
must create an initial connection between the source
replica set and the destination sharded cluster before you can start to
sync data.
To connect cluster0
to cluster1
with mongosync
, enter the
following command:
mongosync \ --cluster0 "<cluster0_connection_string>" \ --cluster1 "<cluster1_connection_string>"
Follow the connection instructions
for your cluster architecture to format your connection strings and
connect to the mongos
instance in your cluster.
Start synchronization
Call the start endpoint to initiate data synchronization.
To sync from a replica set to a sharded cluster, set the
sharding
option for the start
command to shard collections on
the destination cluster. For more information, see
Sharding Parameters.
Use the sharding.shardingEntries
parameter to specify the collections
to shard. Collections that you do not list in this array replicate as
unsharded. For more information, see
Shard Replica Sets and
Choose a Shard Key.
The following example starts a sync from a replica set to a sharded cluster:
Request
curl localhost:27182/api/v1/start -XPOST \ --data ' { "source": "cluster0", "destination": "cluster1", "sharding": { "createSupportingIndexes": true, "shardingEntries": [ { "database": "accounts", "collection": "us_east", "shardCollection": { "key": [ { "location": 1 }, { "region": 1 }, ] } } ] } } '
Response
{"success":true}
Next Steps
You can finalize a migration and transfer your application workload from the
source to the destination cluster using the mongosync
cutover process.
Limitations
You cannot use the reverse endpoint between a replica set and a sharded cluster.
mongosync
allows users to rename collections that thesharding.shardingEntries
option includes during sync with some limitations. For details, see Renaming During Sync.If you use the
sharding.createSupportingIndexes
option, the indexes are automatically created on the destination cluster during the sync. You cannot create these indexes afterwards on the source cluster.If you want to create an index to support shard keys manually, you must create the index before
mongosync
starts or after the migration is complete andmongosync
has stopped.
If the source replica set has arbiters, the source replica set must have more than 2 non-arbiter nodes and you must sync from a non-arbiter node.
For more details, see Limitations.