DDS is accessible through an EIP in a public network or an ECS in a private network.
DDS is compatible with MongoDB.
MongoDB can export data from a database into a JSON file. Such a JSON file can then be used to import the data to MongoDB databases. 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.
Create and log in to an ECS. For details, see "Creating and Logging In to a Windows ECS" or "Creating and Logging In to a Linux ECS" in the Elastic Cloud Server User Guide.
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 an unencrypted 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/***/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 an unencrypted 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/***/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