This topic describes how to import and export data in a cloud database.
Data export
You can export database content to a file in JSON or CSV format. Each row in the exported file corresponds to a record in the database.
Export format |
Fields required |
Default exported content |
Recommended scenario |
JSON format |
No |
By default, all content is exported. The _id field is always exported even when you specify other fields. |
Data backup |
CSV format |
Required |
Only the specified fields are exported. |
Data analysis |
Procedure
On the Cloud database management page, click your target database.
On the Data tab, click Export.
On the export page, select an Export format, enter the Fields to export, and then click OK.
When you export data from a cloud database, some data type information may be lost. The data may not be identical to the original data if you re-import it.
If your collection contains a large amount of data, the export may take a long time. After the export is complete, your browser automatically downloads the file.
Data import
You can import a JSON or CSV file into a database. Each row in the imported file corresponds to a record in the database.
A JSON file must meet the following format requirements:
Each line must be a complete JSON object. It cannot be a JSON array or a primitive data type.
In the JSON-formatted data, the key in each key-value pair cannot start or end with a period (.), and cannot contain consecutive periods (..).
Key names cannot be duplicates.
For a CSV file, the first row is used as the key names, separated by commas (,). The remaining rows are the data records that correspond to the key names in the first row.
The import supports two Conflict handling modes.
Insert mode: The system attempts to insert the data from the file. If a primary key conflict or a unique index conflict occurs during the import, the record is ignored. The remaining data is not affected.
Upsert mode: The system checks if a record exists. If the record exists, it is updated. If the record does not exist, it is inserted. If a unique index conflict occurs, the import operation is aborted.
Procedure
On the Cloud database management page, click the target database.
On the Data tab, click Import.
On the import page, click Upload File. Select a local file to upload. Then, select a conflict handling mode and click OK.
NoteIf the file does not contain an _id field, an _id is automatically generated during the import.
If the file contains an _id field, it must be in the oid format. For example:
{"_id":{"$oid":"639be0d05321300af2bd273d"},"name":"test"}.The format of the import file must be the same as the export file format. The file must use UTF-8 encoding. The maximum size for an import file is 50 MB.
The import operation is not an atomic operation. Some data may be imported successfully while other data may fail to import.
If you import a large amount of data, the import may take a long time. Wait for the import to complete.
Error code descriptions
Error code |
Description |
SERVER_BUSY |
The server is busy. Try again later. |
INVALID_FILE_FORMAT |
An error occurred with the file format during import. Check the file format. |
DUPLICATE_KEY_ERROR |
A unique index conflict occurred during import. Check your original data, the data to be imported, and the unique index settings. |
INTERNAL_ERROR |
A server-side error occurred. Retry the operation. If the error persists, submit a ticket. |