Docs Menu
Docs Home
/
MongoDB Atlas
/ / /

Migrate with mongomirror

On this page

  • Prerequisites
  • Upgrade Path
  • Download mongomirror
  • mongomirror Process
  • Run mongomirror
  • Switch to Atlas
  • Monitoring
  • Performance
  • Command Syntax, Options, and Examples
  • Troubleshooting

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.

  • 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 or M2/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 the mongomirror 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.

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:

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, and backup 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 and readAnyDatabase 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 and readAnyDatabase roles, as well as read access on the local 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" ]
    }
    )

The destination Atlas deployment:

  • Can't be an M0 Free cluster, M2, or M5 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, or

    • If 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?.

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.

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

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.

When you start mongomirror, it:

  1. Connects to Atlas over TLS/SSL.

  2. Performs an initial sync, copying collections from the existing MongoDB replica set to the destination cluster in Atlas.

  3. 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 the config 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:

1

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.

2
  1. If it's not already displayed, select the organization that contains your project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your project from the Projects menu in the navigation bar.

  3. In the sidebar, click Database Access under the Security heading.

    The Database Access page displays.

3

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:

  1. If it isn't already displayed, click the Database Users tab.

  2. Click Add New Database 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.

4

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, or

  • If set up for VPC peering, either the peer's VPC CIDR block (or a subnet) or the Security Group of the peer VPC.

5
  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. If it's not already displayed, click Clusters in the sidebar.

    The Clusters page displays.

6

Click Connect for the Atlas cluster into which you want to migrate data.

7

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.

  1. From the Connect dialog box, click Shell.

  2. 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
  3. 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.

8

To complete the migration process, 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.

1

This ensures that no additional writes occur on the source cluster.

2

This signifies that the source and destination clusters are in a consistent state.

3

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

4

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.

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"}}}}

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.

For mongomirror syntax, options, and examples, see the mongomirror reference page.

For mongomirror troubleshooting, see Common Post-Validation Errors for Live Migration (Pull).

Back

Self-Managed Tools