DDS supports access through EIPs by enabling public accessibility. You can also access a database through an ECS in the private network.
Before migrating data from a MongoDB database to DDS, transfer data to a .json file using the mongoexport tool. This section guides you on how to import the data from the JSON files to DDS using the mongoimport tool on the ECS or the device 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 is successfully exported. x indicates the number of exported data records.
exported x records
gzip exportfile.json
Compressing the file helps reduce the time needed to transmit all the data. The compressed file is exportfile.json.gz.
Select an uploading method based on the OS you are using. In Linux, for example, run the following command:
scp <IDENTITY_FILE> <REMOTE_USER>@<REMOTE_ADDRESS>:<REMOTE_DIR>
In Windows, upload exportfile.json.gz to the ECS using file transfer tools.
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 is successfully imported. x indicates the number of imported data records.
imported x records