Migrating Data Between Service Instances
The intent of this document is to specify how to migrate data from on MongoDB instance to another, regardless of its topology (single or replicated cluster).
For the following steps you can install the MongoDB CLI tool on your local machine or use the binaries shipped with on every MongoDB virtual machine.
The following steps must be executed on the primary, if you are running a cluster.
You can discover which node is the primary with db.adminCommand({replSetGetStatus:1})
.
Backup Data
First, make a local copy of the data on your database. The database name is the deployment name.
You should prefer to use the admin
credentials specified in the instance deployment manifest
under properties.mongodb.admin_username
and properties.mongodb.admin_password
.
# When the Service Instance is SSL, use `--ssl` `--sslCAFile=<your-ca-file-path>`.
mongodump --username=<admin_username> --password=<admin_password> \
--authenticationDatabase=admin --db=<deployment-name> --host=<primary-addr> \
--authenticationMechanism=SCRAM-SHA-256
Restore Data
After creating a new Service Instance according to your needs, you must restore the backup.
Retrieve the admin
credentials for the new Service Instance, and execute the restore command below.
# When the Service Instance is SSL, use `--ssl` `--sslCAFile=<your-ca-file-path>`.
mongorestore --drop --username=<admin_username> --password=<admin_password> \
--authenticationDatabase=admin --db=<new-deployment-name> --host=<primary-addr> \
<dump-path>/<database-to-restore> --authenticationMechanism=SCRAM-SHA-256
You can also specify the BSON file for a collection directly with:
mongorestore --username=<admin_username> --password=<admin_password> \
--authenticationDatabase=admin --db=<new-deployment-name> --host=<primary-addr> \
<dump-path>/<database-to-restore>/<collection-to-restore>.bson \
--authenticationMechanism=SCRAM-SHA-256
Finalization
With data restored, you can delete the old Service Instance and bind your application or create new service keys.
For more information, please refer to the mongodb documentation here