Transfer instructions

This article moves from MySQL and MongoDB to a cloud development database, and other database migrations are much the same.

Migration can be roughly divided into the following steps:

  • Export the database from MySQL and MongoDB to JSON or CSV format
  • Create a cloud development environment
  • Create a new collection into the cloud development database
  • Import a JSON or CSV file within the collection

export

MySQL > export MySQL data

In the following flow, we use Navicat for MySQL to export. You can also use other MySQL export tools.

1. Export the file to CSV format

Select table to export:

Select CSV as the type:

Note: In step 4, we need to check the header that contains the column

In the exported CSV file, the first line contains all the key names, and the remaining lines contain the key values corresponding to the first line. Something like this:

2. Export it in JSON format

Similarly, we export the selected table to JSON format:

Use the default values for the remaining steps.

Exported appearance:

We divide the array and end up like this:

2. Export MongoDB data

First let’s start the Mongod service:

Do not close this terminal after startup.

1. Export the file to CSV format

Open a new terminal and type the following command:

Mongoexport - db database < > -- collection collection < name > -- type CSV -f < field name 1 [field name, 2) > - < output file path > oCopy the code

For more detailed parameter descriptions, see the MongoDB documentation.

Note: When exporting the CSV format, you must specify the columns to be exported. Otherwise, the following error message is displayed: ⚠️ CSV mode requires a field list

Exported appearance:

2. Export it in JSON format

Open a new terminal and type the following command:

Mongoexport - db database < > -- collection collection < name > - < output file path > oCopy the code

For more detailed parameter descriptions, see the MongoDB documentation.

Exported appearance:

The import

1. Create a cloud environment

If you already have a cloud environment, you can skip this step and open the Cloud Development console to create a cloud environment:

After creating an environment, wait 2 minutes for the environment initialization process.

2. Database import

Click Add Collection to create a collection:

After creating it, we click on it and import it:

Select the CSV or JSON file we exported earlier.

Note:

There are two modes of conflict handling: Insert and Upsert

  • In Insert mode, new records are always inserted during import. The same file cannot have duplicate _ID fields or the same _ID fields as existing records in the database. If you want existing data not to be overwritten, you should use Insert mode.
  • The Upsert mode determines whether the record exists, updates the record if it exists, and inserts a new record otherwise. If you do not want to generate redundant and repetitive data, you should use the Upsert pattern.

Here we choose Upsert mode:

After the import process is complete, the imported data can be seen in the database:

Product introduction

Cloud Development (TCB) is a cloud native integrated development environment and tool platform provided by Tencent Cloud. It provides developers with highly available, automatic and flexible expansion of back-end cloud services, including computing, storage, hosting and other serverless capabilities, which can be used for cloud integrated development of various end applications (small programs, Public account, Web application, Flutter client, etc.) to help developers build and manage back-end services and cloud resources in a unified manner, avoiding tedious server construction, operation and maintenance during application development. Developers can focus on the implementation of business logic, with lower development threshold and higher efficiency.

Open cloud development: console.cloud.tencent.com/tcb?tdl_anc…

The product documentation: cloud.tencent.com/product/tcb…

Technical documentation: Cloudbase.net? From =10004

[Technical Communication Group] Add a little assistant wechat: Tcloudedu1

Latest news follow wechat official account [Tencent Yunyun Development]