Migrate with mongomirror

mongomirror is a utility for 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.


mongomirror does not import user/role data.



  • The source MongoDB deployment must be a replica set. If the source is a standalone MongoDB deployment, convert to a replica set first to use mongomirror. See Convert a Standalone to a Replica Set.

  • The source replica set must run MongoDB version 2.6 through 4.0.

  • The source MongoDB replica set cannot be an M0 (Free Tier) or M2/M5 shared cluster.

  • You should not change the featureCompatibilityVersion flag at any time during the procedure.

  • You should not 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.

    Contact MongoDB Support if you believe renaming or dropping a collection needs to occur during the migration process. From the Atlas UI, click Support to open a support ticket.


  • The target Atlas cluster must be a replica set.
  • The target Atlas cluster should be empty or run mongomirror with the --drop option.
  • The target Atlas cluster cannot be an M0 (Free Tier), M2, or M5 shared cluster.
  • The target Atlas cluster MongoDB version must be the same as or later than the source cluster MongoDB version.
  • You should not change the featureCompatibilityVersion flag at any time during the procedure.



Set up MongoDB user in the source replica set.

If the source replica set requires authentication, you must include user credentials when running mongomirror. You must specify a MongoDB user with backup role. If no such user exists, create the user in your source MongoDB replica set. For example, if the source replica set uses SCRAM-SHA1 authentication:

  1. Connect a mongo shell to the primary.

  2. Switch to the admin database and create a user with the backup role.

    use admin
        user: "mySourceUser",
        pwd: "mySourceP@$$word",
        roles: [ "backup" ]

Make note of the username and password for this user, as you must specify these credentials when running mongomirror.


Set up MongoDB user in the target Atlas cluster.

You must specify an Atlas MongoDB user with the Atlas admin role to run mongomirror. See Add MongoDB Users for documentation on creating an Atlas MongoDB user.

If no such user exists, create the user:

  1. Go to Clusters view, select the Security tab, and then Users.
  2. Click Add New User.
  3. 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.


Open the connect dialog.

From the Clusters view, click Connect for the Atlas cluster into which you want to migrate data.


Update IP Whitelist.

If the host where you will run mongomirror is not in the IP Whitelist, update the list. You can specify either:

  • The public IP address of the server on which mongomirror will run, or
  • If set up for VPC peering, either the peer’s VPC CIDR block (or a subnet) or the peer VPC’s Security Group.

Copy the target cluster host information.

  1. Click Connect Your Application.
  2. Click I am using driver 3.4 or earlier.
  3. Copy the connection string and paste into your preferred text editor.

The connection string should look similar to the following example. This example has been broken into multiple lines for readability:


Copy the value of replicaSet and append the host list as comma separated values, similar to the following:


Use this value for the --destination option in the next step.


Start mongomirror.

Start mongomirror with the following options:

  • --host set to the host string of the source cluster.
  • --ssl set to true if the source cluster has TLS/SSL enabled.
  • --username to the source cluster username created for this procedure.
  • --password to the password for the source cluster username.
  • --authenticationDatabase to the database in the source cluster where the username specified to –username was created.
  • --destination to the Atlas cluster host string.
  • --destinationUsername to the target Atlas cluster username.
  • --destinationPassword to the password for the target Atlas cluster username.

Your final command should resemble the following example:

mongomirror --host "MySourceRS/,," \
   --ssl "true" \
   --username "mySourceUser" \
   --password "mySourceP@$$word" \
   --authenticationDatabase "admin" \
   --destination "myAtlasRS/,," \
   --destinationUsername "myAtlasAdminUser" \
   --destinationPassword "atlasPassword"

See Options for more mongomirror options.

When you start mongomirror:

  1. First, mongomirror performs an initial sync, copying collections from the existing MongoDB replica set to the target cluster in Atlas. mongomirror does not copy the config database.


    Starting in version 0.5.0, 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. For more information on foreground index builds, see Index Build Operations on a Populated Collection.

  2. After the initial sync, mongomirror continuously tails the replica set’s oplog for incoming changes and replays them on the target cluster in MongoDB Atlas.

Once started, mongomirror runs continuously until you shut down the process. To fully migrate to the Atlas, continue on to Switch to Atlas steps.

Switch to Atlas

After the mongomirror has performed the initial sync and has been tailing the replica set’s oplog, to switch over to Atlas cluster:


Stop write operations to the source replica set.


Wait for the Atlas cluster to be up to date with the last writes.

Continue to run mongomirror to finish tailing the oplog.


Stop mongomirror.

Once the Atlas cluster is up to date, stop mongomirror.


Update client applications to use Atlas cluster.

Update client applications to connect to the Atlas cluster.

For details on connections to Atlas, see Connect via Driver.

Additional Information

For more information on mongomirror, including behavior, options, and examples, see the mongomirror reference page.