Migrate with mongomirror
On this page
mongomirror
is a tool for manually migrating data from an existing
MongoDB replica set to a MongoDB Atlas replica set.
mongomirror
does not require you to shut down your existing
replica set or applications, and does not import user or role data
or copy the config
database.
Use mongomirror
for:
Running a one-time migration of a dataset into a MongoDB Atlas cluster from a MongoDB deployment hosted outside of MongoDB Atlas.
Running a one-time migration of a dataset from one Atlas cluster into another Atlas cluster.
See also Choosing a Data Import and Migration Tool.
Prerequisites
Source MongoDB Deployment
The source MongoDB deployment must be a replica set. If the source is a standalone MongoDB deployment, before running
mongomirror
, convert the standalone to a replica set.The source replica set must run MongoDB version 2.6 or higher.
The source MongoDB replica set can't be an
M0
Free cluster orM2/M5
shared cluster.The source MongoDB replica set can't contain data in time series collections.
Don't change the
featureCompatibilityVersion
flag at any time during the procedure.When you migrate from MongoDB 4.4 or earlier to an Atlas cluster that runs MongoDB 5.0 or later, drop any geoHaystack indexes from your collections.
mongomirror
is not compatible with TTL indexes. Drop any existing TTL indexes and rebuild them when the migration process is complete. If you do not want to drop an existing index because it is important for query performance, contact support for alternative options.Don't make any namespace changes during the migration process, such as using the
renameCollection
command or executing an aggregation pipeline that includes the$out
aggregation stage.You can't use the
renameCollection
command or the$out
aggregation stage as part of initial sync, which runs as a part of themongomirror
process.You must not restart the primary during the initial sync stage of the migration.
If your MongoDB deployment contains indexes with keys which exceed the Index Key Limit, before you start the live migration procedure, modify indexes so that they do not contain oversized keys.
Required Access on Source Replica Set
mongomirror
must have network access to the source replica set. If the
source replica set requires authentication, you must include user credentials
when running mongomirror
. You must specify a database user with, at a
minimum, the following privileges:
Read all databases and collections. The
readAnyDatabase
role on theadmin
database covers this requirement.Read the oplog. See Oplog Access.
Run the
getParameter
command.
If no such user exists, create the user in your source MongoDB replica set.
Different MongoDB server versions have different built-in roles. Select a
built-in role based on your MongoDB Server version and run the appropriate
commands in the mongosh
:
For source clusters a user must have the
readAnyDatabase
,clusterMonitor
, andbackup
roles.To verify that the database user who will run the live migration process has these roles, run the db.getUser() command on the
admin
database.use admin db.getUser("admin") { "_id" : "admin.admin", "user" : "admin", "db" : "admin", "roles" : [ { "role" : "backup", "db" : "admin" }, { "role" : "clusterMonitor", "db" : "admin" } { "role" : "readAnyDatabase", "db" : "admin" } ] } ... In addition, the database user from your source cluster must have the role to read the oplog on your
admin
database. To learn more, see Oplog Access.For source clusters running MongoDB 3.4 a user must have, at a minimum, both
clusterMonitor
andreadAnyDatabase
roles. For example:use admin db.createUser( { user: "mySourceUser", pwd: "mySourceP@$$word", roles: [ "clusterMonitor", "readAnyDatabase" ] } ) For source clusters running MongoDB 3.2 a user must have, at a minimum, both
clusterManager
andreadAnyDatabase
roles, as well as read access on thelocal
database. This requires a custom role, which you can create with the following commands:use admin db.createRole( { role: "migrate", privileges: [ { resource: { db: "local", collection: "" }, actions: [ "find" ] } ], roles: ["readAnyDatabase", "clusterManager"] } ) db.createUser( { user: "mySourceUser", pwd: "mySourceP@$$word", roles: [ "migrate" ] } ) For source clusters running MongoDB 2.6 or 3.0 a user must have, at a minimum, the
readAnyDatabase
role. For example:use admin db.createUser( { user: "mySourceUser", pwd: "mySourceP@$$word", roles: [ "readAnyDatabase" ] } )
Destination Atlas Deployment
The destination Atlas deployment:
Can't be an
M0
Free cluster,M2
, orM5
Shared cluster.Can't be a Serverless instance.
Must be a replica set.
Must have the version that is the same as or later than the source cluster MongoDB version. See Upgrade Path.
Must not contain any namespaces that overlap with the source cluster. If
mongomirror
detects overlapping namespaces on the destination cluster it fails before starting the process. If your destination cluster contains overlapping namespaces, delete all data from the destination cluster with--drop
, or list the namespaces to import from the source cluster with--includeNamespace
.Must include in its IP access list either:
The public IP address of the server on which
mongomirror
is running, orIf set up for VPC peering, either the peer's VPC CIDR block (or a subset) or the Security Group of the peer VPC.
Note
To find the public IP address for any node in your cluster, use the
nslookup
tool from the command line. To learn more, see Do Atlas cluster's public IPs ever change?.
Required Access on the Destination Cluster
mongomirror
must have network access to the destination cluster.
You must specify a database user with the Atlas admin
role to run mongomirror
. To learn more, see Add Database Users.
Upgrade Path
Important
mongomirror
is not supported for migrations between MongoDB 6.0+ source
clusters and 6.0+ destination clusters.
You can't use mongomirror
to migrate from a source replica set 6.0.x
or later to a destination replica set 6.0.x or later.
You can use mongomirror
to migrate from a source replica set on previous
versions to a destination replica set with MongoDB version 6.0.
Alternatively, you can upgrade your source replica set to 6.0.13+ or 7.0.8+ and use this live migration procedure to migrate an upgraded replica set to Atlas.
mongomirror
supports the following migration paths.
Source Replica Set MongoDB Version | Target Atlas Replica Set MongoDB Version |
---|---|
5.0 | 6.0 |
4.4 | 6.0 |
4.2 | 6.0 |
4.0 | 6.0 |
3.6 | 6.0 |
3.4 | 6.0 |
3.2 | 6.0 |
3.0 | 6.0 |
2.6 | 6.0 |
Download mongomirror
Note
On macOS 64-bit, a security alert appears when you first try to open
the mongomirror
file after you have downloaded it. To proceed, see
Open an app by overriding security settings.
Operating System | Download |
---|---|
Amazon Linux 1 | |
Amazon Linux 2 | |
Debian 9.2 | |
Debian 10 | |
macOS 64-bit | |
RHEL 6.2 | |
RHEL 7.0 | |
RHEL 7.1 PPC64LE | |
RHEL 7.2 s390x | |
RHEL 8.0 | |
RHEL 8.1 PPC64LE | |
SLES 12 | |
SLES 15 | |
Ubuntu 14.04 | |
Ubuntu 16.04 | |
Ubuntu 16.04 ARM | |
Ubuntu 18.04 | |
Ubuntu 18.04 ARM | |
Ubuntu 20.04 | |
Ubuntu 20.04 ARM | |
Windows |
mongomirror
Process
When you start mongomirror
, it:
Connects to Atlas over TLS/SSL.
Performs an initial sync, copying collections from the existing MongoDB replica set to the destination cluster in Atlas.
After the initial sync, continuously tails the replica set's oplog for incoming changes and replays them on the destination cluster in Atlas.
mongomirror
doesn't copy theconfig
database.mongomirror
uses wire compression if you enable it on either the source or the destination cluster and use--compressors
to specify which compression libraries to allow.mongomirror
builds all indexes on the destination cluster in the foreground, regardless of how the indexes were built on the source cluster. Foreground index builds block all other operations on the database. To learn more, see Index Build Operations on a Populated Collection.
Once started, mongomirror
runs continuously until you shut it down:
If you shut down
mongomirror
during the initial sync stage, before you restartmongomirror
, check that the destination cluster is empty, or runmongomirror
with--drop
.If you shut down
mongomirror
during the oplog tailing stage, the process stops tailing the oplog. You can restartmongomirror
to continue tailing from the last processed oplog record using--bookmarkFile
.
Run mongomirror
Set up database user in the source replica set.
If the source replica set requires authentication, you must include
user credentials when running mongomirror
. For requirements, see
Required Access on Source Replica Set.
Make note of the username and password for this user, as you must
specify these credentials when running mongomirror
.
In Atlas, go to the Database Access page for your project.
If it's not already displayed, select the organization that contains your project from the Organizations menu in the navigation bar.
If it's not already displayed, select your project from the Projects menu in the navigation bar.
In the sidebar, click Database Access under the Security heading.
The Database Access page displays.
Set up a database user in the target Atlas cluster.
You must specify a database user with the
Atlas admin
role to run mongomirror
.
See Add Database Users for documentation on creating a database
user.
If no such user exists, create the user:
If it isn't already displayed, click the Database Users tab.
Click Add New Database User.
Add an Atlas admin user.
Make note of the username and password selected for the new
user, as you must specify these credentials when running
mongomirror
.
Update IP Access List.
If the host where you will run mongomirror
is not in your cluster's
IP Access List, update the list.
You can specify either:
The public IP address of the server on which
mongomirror
will run, orIf set up for VPC peering, either the peer's VPC CIDR block (or a subnet) or the Security Group of the peer VPC.
In Atlas, go to the Clusters page for your project.
If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it's not already displayed, select your desired project from the Projects menu in the navigation bar.
If it's not already displayed, click Clusters in the sidebar.
The Clusters page displays.
Copy the target cluster host information.
You can get your Atlas cluster's hostname information from the Atlas user interface.
Note
You don't need to use a driver to migrate data with mongomirror
.
From the Connect dialog box, click Shell.
From the drop-down list, select 3.4 or earlier. The connection string should look similar to the following example. This example has been broken into multiple lines for readability:
mongodb://<db_username>:<db_password>@ 00.foo.mongodb.net:27017, 01.foo.mongodb.net:27017, 02.foo.mongodb.net:27017/test? ssl=true&replicaSet=myAtlasRS&authSource=admin In a text editor, paste the value of
replicaSet
, add a forward slash (/
), and then append the host list as comma-separated values, as shown in the following example:myAtlasRS/00.foo.mongodb.net:27017,01.foo.mongodb.net:27017,02.foo.mongodb.net:27017
Use this value for --destination
in the next step.
To complete the migration process, switch to Atlas.
Switch to Atlas
After mongomirror
completes the initial sync and tails the replica set's
oplog, you can switch over to the destination Atlas cluster.
Update client applications to use the Atlas cluster.
Update your client applications with the Atlas connection string provided via the Connect button on the cluster panel.
For details on connections to Atlas, see Connect via Drivers.
Monitoring
mongomirror
logs its progress to the standard output in the terminal.
During the initial sync, mongomirror
logs a progress bar for each
collection it copies. For example:
2021-08-09T16:35:50.227-0000 [#....................] park.events 2179/34184 (6.4%) 2021-08-09T16:35:50.227-0000 [#############........] zoo.animals 29000/49778 (58.3%)
When tailing the oplog, mongomirror
logs the lag time, in seconds,
between the most recent oplog entry on the source cluster and the last
processed oplog entry on the destination cluster. For example:
2016-12-12T16:22:17.027-0800 Current lag from source: 6s
A lag time of 6 seconds means that the last oplog entry
mongomirror
processed occurred 6 seconds before the most
recent one available on the source cluster.
Note
The amount of time it takes mongomirror
to catch up may be
greater or less than 6 seconds, depending on the number of entries
that arrive per second.
A lag time of 0 seconds indicates that mongomirror
is processing
entries that arrived less than one second before the latest oplog entry.
If the source cluster has indexes, mongomirror
builds the same indexes
on the destination cluster. The progress log shows the start and end times of
the index building process. To view the progress of the index builds,
you can either:
Use the currentOp command on the primary node of the destination cluster. The
command
field shows information about the running operation. Index building entries look similar to the following:"command" : { "createIndexes" : "perfs", "indexes" : [ { "key" : { "animal" : "text" }, "name" : "animal_text" } ]... Download the mongodb logs for your destination cluster and search for recent entries for index-related lines. Log messages related to index building look similar to the following:
{"t":{"$date":"2021-08-09T16:35:50.227+00:00"},"s":"I", "c":"INDEX", "id":20447, "ctx":"conn1080","msg":"Index build: completed","attr":{"buildUUID":{"uuid":{"$uuid":"c4a62739-bf19-456d-bbd6-7baa29f1063b"}}}}
Performance
To avoid contention for network and CPU resources, run mongomirror
on
hosts other than your replica set's mongod
instance hosts.
mongomirror
affects your source replica set's performance similar to having a secondary:For the initial sync stage, the load scales with the size of your data set.
Once an initial sync completes, the load scales with oplog gigabytes used per hour.
Command Syntax, Options, and Examples
For mongomirror
syntax, options, and examples, see the
mongomirror reference page.
Troubleshooting
For mongomirror
troubleshooting, see
Common Post-Validation Errors for Live Migration (Pull).