Fix This Page
Navigation

Seed with mongorestore

You can use mongodump and mongorestore to seed MongoDB Atlas cluster with data from an existing MongoDB standalone, replica set or a sharded cluster.

Considerations

  • mongorestore errors when merging in MongoDB users and roles data into Atlas. If using mongorestore version 3.4 or greater, you can exclude specific collections from the restore using --nsExclude option.

  • mongodump excludes the content of the local database in its output.

  • mongodump can adversely affect performance of the mongod. If your data is larger than system memory, the mongodump will push the working set out of memory.

    If you are performing a switch-over from a non-Atlas deployment to an Atlas cluster, you should consider your downtime tolerance and the required state of the data (e.g. being fully up to date) at the time of the switch-over.

  • If the data must be fully in sync with the non-Atlas deployment before switching over, after uploading via mongorestore, additional steps must be taken to bring the Atlas cluster in sync with an existing cluster.

Procedure

The following tutorial uses mongodump and mongorestore to stream data over a network device via a pipe to upload data from an existing deployment to an Atlas cluster:

1

Set up MongoDB user in the source replica set.

If the source deployment requires authentication, you must specify a source MongoDB user that has privileges to read any database. For example, a user with backup role provides these privileges.

If the source deployment requires authentication and 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
    db.createUser( { user: "mySourceUser", pwd: "mySourceP@$$word", roles: [ "backup" ] } )
    
2

Set up MongoDB user in the target Atlas cluster.

To run mongorestore to write to Atlas cluster, you must specify a MongoDB user that has readWriteAnyDatabase and dbAdminAnyDatabase privileges in the Atlas cluster. For example, a user with Atlas admin role provides these privileges.

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

Open the connect dialog.

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

4

Update IP Whitelist.

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

  • The public IP address of the server on which mongorestore 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.
5

Copy the target cluster host information.

From the connect dialog, get the cluster host information. This information is specified to mongorestore in the --host option.

If the Atlas cluster is a replica set, you must also retrieve the replica set name. For example:

myAtlasRS/atlas-host1:27017,atlas-host2:27017,atlas-host3:27017
6

Run mongodump and mongorestore.

For example, if the source is a replica set that uses SCRAM-SHA1 authentication, the following operation pipes the output from mongodump directly to mongorestore.

Note

mongorestore errors when merging in MongoDB users and roles data into Atlas. If using mongorestore version 3.4 or greater, you can exclude specific collections from the restore using --nsExclude option.

The following operation assumes a version 3.4 mongorestore and includes the --nsExclude option.

mongodump --host sourceRS/source-host1:27017,source-host2:27017,source-host3:27017 --archive --ssl -u mySourceUser -p 'mySourceP@$$word' --authenticationDatabase admin | \
mongorestore --host myAtlasRS/atlas-host1:27017,atlas-host2:27017,atlas-host3:27017 --archive --ssl -u myAtlasAdminUser -p 'atlasP@$$assw0Rd' --authenticationDatabase admin --nsExclude 'admin.system.users' --nsExclude 'admin.system.roles'

Add/edit the mongodump command line options as appropriate for your deployment. See mongodump for more mongodump options and mongorestore for more for more mongorestore options.

Additional Information

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