• Document Database Service

dds
  1. Help Center
  2. Document Database Service
  3. User Guide
  4. Getting Started
  5. Migrating Data
  6. Importing Data

Importing Data

Scenarios

This section guides you on how to import the data from the JSON files to DDS using the mongoimport tool on the ECS.

Procedure

  1. Log in to the ECS prepared in section Preparing for Data Migration.
  2. Upload the data to be imported to the ECS.

    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>

    • IDENTITY_FILE indicates the directory where the exportfile.json.gz file is located. The file access permission is 600.
    • REMOTE_USER indicates the ECS OS user in 1.
    • REMOTE_ADDRESS indicates the ECS address in 1.
    • REMOTE_DIR indicates the directory of the ECS to which the exportfile.json.gz file is uploaded.

    In Windows, upload exportfile.json.gz to the ECS using file transfer tools.

  3. Decompress the package.

    gzip -d exportfile.json.gz

  4. Import the JSON file to the DDS database.

    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>

    • DB_ADDRESS indicates the DB instance IP address.
    • DB_PORT indicates the database port.
    • AUTH_DB indicates the database that authenticates DB_USER. Generally, this value is admin.
    • DB_USER indicates the account name of the database administrator.
    • DB_NAME indicates the name of the database that data is to be imported to.
    • DB_COLLECTION indicates a collection of databases that data is to be imported to.
    • DB_PATH indicates the path where the .json file is located.

    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

  5. Check the results.

    If information similar to the following is displayed, the data is successfully imported. x indicates the number of exported data records.

    imported x records