Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Migrating Data

Updated on 2022-02-22 GMT+08:00

Scenarios

DDS supports access through EIPs by enabling public accessibility. You can also access a database through an ECS in a private network.

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 the device that can access DDS.

Prerequisites

  1. An ECS or a device that can access DDS is ready for use.
    • For details on how to connect to a DDS DB instance through a private network and how to create and log in to an ECS, 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.
  2. A migration tool has been installed on the prepared ECS.

    For details on how to install the migration tool, see How Can I Install a MongoDB Client?

    NOTE:

    The MongoDB client provides the mongoexport and mongoimport tools.

Exporting Data

  1. Log in to the ECS or the device that can access DDS.
  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 from which data will be exported.
    • DB_COLLECTION indicates the collection of the database from which data will 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 192.168.1.21 --port 8635 --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase admin -u rwuser --db test02 --collection Test --out /tmp/mongodb/export/exportfile.json

  3. Check the result.

    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.

Importing Data

  1. Log in to the ECS or the device that can access DDS.
  2. Upload the data to be imported to the ECS or the device that can access DDS.

    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.
    • REMOTE_ADDRESS indicates the ECS address.
    • 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 to which data will be imported.
    • DB_COLLECTION indicates the collection of the database to which data will be imported.
    • 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 result.

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

    imported x records

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback