• Document Database Service

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

Exporting Data


Before exporting data from a MongoDB database to DDS, dump the data first.


  1. Log in to the ECS prepared in section Preparing for Data Migration.
  2. Use the mongoexport tool to transfer data from the source database to a .json file.

    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>

    • DB_ADDRESS indicates the database address.
    • DB_PORT indicates the database port.
    • AUTH_DB indicates the database for storing DB_USER information. Generally, this value is admin.
    • DB_USER indicates the database user.
    • DB_NAME indicates the name of the database that data is to be exported from.
    • DB_COLLECTION indicates a collection of databases from which data is to be exported.
    • 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. After the command is executed, the exportfile.json file will be generated:

    ./mongoexport --host --port 8635 --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase admin -u rwuser --db test02 --collection Test --out /tmp/mongodb/export/exportfile.json

  3. Check the results.

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

    exported x records

  4. Compress the exported .json file.

    gzip exportfile.json

    Compressing the file helps reduce the time needed to transmit all the data. The compressed file is exportfile.json.gz.