I want to migrate a collection from one Mongo Atlas Cluster to another. How do I go about in doing that?
Asked
Active
Viewed 1,560 times
1 Answers
3
There are 2 poosible approaches here:
- Migration with downtime: stop the service, export the data from the collection to some 3rd location, and then import the data into the new collection on the new cluster, and resume the service.
- But there's a better way: using the MongoMirror utility. With this utility, you can sync collections across clusters without any downtime. the utility first syncs the db (or selected collections from it) and then ensures subsequent writes to the source are synced to the dest.
following is the syntax I used to get it to run:
./mongomirror --host atlas-something-shard-0/prod-mysourcedb--shard-00-02-pri.abcd.gcp.mongodb.net:27017 \
--username myUserName \
--password PASSWORD \
--authenticationDatabase admin \
--destination prod-somethingelse-shard-0/prod-mydestdb-shard-00-02-pri.abcd.gcp.mongodb.net:27017 \
--destinationUsername myUserName \
--destinationPassword PASSWORD \
--includeNamespace dbname.collection1 \
--includeNamespace dbname.collection2 \
--ssl \
--forceDump
Unfortunately, there are MANY pitfalls here:
- ensure your user has the correct role. this is actually covered in the docs so read the relevant section closely.
- to correctly specify the host and destination fields, you'll need to obtain both the RS name and the primary instance name. One way to get these is to use the mongosh tool and run rs.conf() on both source and destination clusters. The RS name is specified as "_id" in the command's output, and the instances are listed as "members" in the output. You'll want to take the primary instance's "host' field. the end result should look like RS-name/primary-instance-host:port
- IF you specify replica-set, you MUST specify the PRIMARY instance. Failing to do so will result in an obscure error (EOF something).
- I recommend adding the forceDump flag (at least until you manage to get it to run for the first time).
- If you specify non-existing collections, the utility will only give one indication that they don't exist and then go on to "sync" these, rather than failing.

FuzzyAmi
- 7,543
- 6
- 45
- 79
-
I specify primary instance and replicaSetName but still get obscure EOF error. Are there any other tips on what might be causing it? I can connect fine using mongo cli from that instance using the same credentials. – Alexander Korzhykov Jun 22 '22 at 00:13