Export Data Using mongodump

You can use the mongodump utility to export your MongoDB® data at ScaleGrid to your local machine. The mongodump version should be the same version as your MongoDB cluster. Please see the Availability section on mongodump page for installation instructions.

mongodump Database Export - SSL Not Enabled

mongodump -u admin -p <admin password> --host <hostname:port> --db <database name> --authenticationDatabase=admin

The admin password can be found under the Credential section of the Overview tab of your Cluster Details page, and the hostname and port number information can be retrieved from the Command Line Syntax section at the bottom of the Cluster Details page.

Here is the hostname and port number extracted from the above screenshot:

Hostname: SG-myMongoDB-33681.servers.mongodirector.com
Port number: 27017

mongodump example:

mongodump -u admin -p myPassword --host SG-myMongoDB-33681.servers.mongodirector.com:27017 --db mydb --authenticationDatabase=admin

mongodump Database Export - SSL Enabled

If your MongoDB server is SSL enabled then you have to add the --ssl and --sslCAFile <file.crt> options.

mongodump -u admin -p <admin password> --host <hostname:port> --db <database name> --authenticationDatabase=admin --ssl --sslCAFile=<file.crt>

The SSL CA certificate is available for download on your Cluster Details page Overview tab.

Export All Databases

You can use the same mongodump command without the "--db " option to export all your databases.

mongodump -u admin -p <admin password> --host <hostname:port> --authenticationDatabase=admin --ssl --sslCAFile=<file.crt>

The mongodump creates a folder called dump which is a logical dump of all the data in the database. If for any reasons the mongodump has failed during the export then delete the dump folder and retry it again.

Restore Using mongorestore

You can use the mongorestore command to restore data into your local MongoDB server. If you wish to change the name of the database to which data is restored, simply rename the database folder under the dump folder.

Here is the mongorestore command to restore the dump data to a MongoDB server:

mongorestore -u admin -p <admin password> --host <target hostname:port> --authenticationDatabase=admin --ssl --sslCAFile=<file.crt> ./dump

The ./dump is the folder that is produced by the mongodump command.

📘

Please note that the mongorestore only restores documents that don't already exist. If the document exists, mongorestore will not update it.

You can use the --db and specify the dump path to restore a single database. The dump path of a database is ./dump/.

The --drop command will drop all collections from the target database before restoring data from the dump.

Here is the mongorestore command:

mongorestore -u admin -p <admin password> --drop --db <db name> --host <target hostname:port> --authenticationDatabase=admin --ssl --sslCAFile=<file.crt> ./dump/<db name>

For more mongorestore command options, please see the Options section on mongorestore page.