Skip to main content

Data Import/Export

Collection Management Import

CloudBase supports batch data import, helping you quickly migrate existing data or initialize test data.

Operation Process

  1. Select Collection: Switch to Cloud Development Platform/Collection Management, select target collection.
  2. Start import: Click the "Import" button (supports JSON and CSV formats).
  3. Configure import: Select file format and conflict resolution mode
  4. Execute import: Click the "Import" button to start the data import process

Conflict Resolution Mode

ModeBehaviorApplicable ScenariosNotes
InsertAlways insert new recordsCompletely new data importCannot have duplicate _id
UpsertUpdate if exists, insert if notData update, incremental importDetermine existence based on _id
Tip
  • For the first import: It is recommended to use Insert mode to ensure data integrity
  • Data update: It is recommended to use Upsert mode to avoid duplicate data

Supported File Formats

JSON Format

Encoding requirements: UTF-8 encoding
Format characteristics: Similar to JSON Lines format, with one JSON object per line

{"_id": "user_001", "name": "Zhang San", "age": 25, "email": "zhang@example.com"}
{"_id": "user_002", "name": "Li Si", "age": 30, "email": "li@example.com"}
{"_id": "user_003", "name": "Wang Wu", "age": 28, "email": "wang@example.com"}

CSV Format

Encoding requirements: UTF-8 encoding
Format characteristics: The first row contains field names, and subsequent rows contain data.

_id,name,age,email
user_001,Zhang San,25,zhang@example.com
user_002,Li Si,30,li@example.com
user_003,Wang Wu,28,wang@example.com

Format Requirements and Limitations

JSON Format Specifications

Specification ItemRequirementExample
DelimiterUse the newline character \n to separate recordsOne JSON object per line
Field NamingCannot start or end with ., cannot contain consecutive ...name, name., a..b
Unique Key NamesMust not have duplicate or ambiguous key names{"a": 1, "a": 2}
Time FormatUse the ISODate format{"date": {"$date": "2024-01-15T10:30:00.882Z"}}

Data Integrity Requirements

ModeRequirementDescription
Insert Mode_id must be uniqueNo duplicate _id allowed within the file or in the database
Upsert ModeAllows duplicate _idRecords with the same _id will be updated

Import Results

After the import is completed, the system will display detailed import statistics:

  • Number of successfully imported records
  • Number of failed records and reasons
  • Number of skipped records (e.g., duplicate data)

Collection Management Export

CloudBase supports exporting collection data to files for data backup, analysis, or migration to other systems.

Operation Process

  1. Access the console: Go to the Tencent Cloud Development Platform
  2. Select Collection: Switch to Cloud Development Platform/Collection Management, select the collection to export.
  3. Start export: Click the "Export" button
  4. Configure export: Select export format, save location, and field range
  5. Execute export: Click the "Export" button to start the data export process

Export Format Configuration

JSON Format Export

Features:

  • Retain the complete data structure
  • Supports nested objects and arrays
  • Exports all fields by default

Field Configuration:

  • Without specifying fields: Exports all data (Recommended)
  • Specify fields: Exports only the specified fields

CSV Format Export

Features:

  • Suitable for tabular data analysis
  • Compatible with tools such as Excel
  • Must specify export fields

Field Configuration Example:

// Basic fields export
_id, name, age, email

// Include system fields
_id, name, age, createdAt, updatedAt

Export Options Comparison

FormatField RequirementsData IntegrityApplicable Scenarios
JSONOptionalFull retentionData backup, system migration
CSVRequiredFlattened processingData analysis, Excel processing

Best Practices

  • Data backup: Use JSON format without specifying fields to export complete data.
  • Data analysis: Use CSV format to specify the fields to be analyzed.
  • Large datasets: Export in batches to prevent excessive data volume in a single export operation
  • Nested data: CSV format requires the use of dot notation to access nested fields