mongoexport and mongoimport are backup and restoration tools provided by the MongoDB client. You can install a MongoDB client on the local device or ECS and use the mongoexport and mongoimport tools to migrate your on-premises MongoDB databases or other cloud MongoDB databases to DDS instances.
Before migrating data from a MongoDB database to DDS, transfer data to a .json file using the mongoexport tool. This section describes how to import the data from the JSON files to DDS using the mongoimport tool on the ECS or from some other devices that can access DDS.
For details on how to install the migration tool, see How Can I Install a MongoDB Client?
The MongoDB client provides the mongoexport and mongoimport tools.
The SSL connection is used as an example. If you select a common connection, delete --ssl --sslAllowInvalidCertificates from the following command.
./mongoexport --host <DB_ADDRESS> --port <DB_PORT> --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase <AUTH_DB> -u <DB_USER> --db <DB_NAME> --collection <DB_COLLECTION> --out <DB_PATH>
Enter the database administrator password when prompted:
Enter password:
The following is an example. After the command is executed, the exportfile.json file will be generated:
./mongoexport --host 192.168.1.21 --port 8635 --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase admin -u rwuser --db test02 --collection Test --out /tmp/mongodb/export/exportfile.json
If information similar to the following is displayed, the data has been successfully exported. x is the number of exported data records.
exported x records
gzip exportfile.json
Compressing the file helps reduce the time needed to transmit the data. The compressed file is exportfile.json.gz.
Select an uploading method based on the OS you are using.
scp <IDENTITY_FILE> <REMOTE_USER>@<REMOTE_ADDRESS>:<REMOTE_DIR>
gzip -d exportfile.json.gz
The SSL connection is used as an example. If you select a common connection, delete --ssl --sslAllowInvalidCertificates from the following command.
./mongoimport --host <DB_ADDRESS> --port <DB_PORT> --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase <AUTH_DB> -u <DB_USER> --db <DB_NAME> --collection <DB_COLLECTION> --file <DB_PATH>
Enter the database administrator password when prompted:
Enter password:
The following is an example:
./mongoimport --host 192.168.1.21 --port 8635 --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase admin -u rwuser --db test02 --collection Test --file /tmp/mongodb/export/exportfile.json
If information similar to the following is displayed, the data has been successfully imported. x is the number of imported data records.
imported x records