# Database Import

Cloud Base supports the import of existing CSV and JSON data from a file. You can import data using either the Cloud Base console or the HTTP API.

# Import Using Cloud Base Console

To import data, open the Cloud Base console, switch to the "Database" tab, select the collection to import data to, and click the "Import" button.

Database

Select the CSV or JSON file you want to import, select the conflict processing mode, and click the "Import" button to start the import.

# Import Using HTTP API

For more information, refer to the database export using HTTP API documentation.

# File Formats

JSON and CSV files must be encoded in UTF-8, with content similar to the MongoDB export format. For example:

JSON:

{
    "_id": "xxxxxx",
    "age": 45
}
{
    "_id": "yyyyyy",
    "age": 21
}

CSV:

_id,age
xxxxxx,45
yyyyyy,21

Notes:

  1. JSON data is not Array type, but similar to JSON Lines, with \n used to separate each record object, rather than a comma.

  2. The key name of a JSON data key-value pair cannot start or end with . (e.g., ".a" or "abc.") and cannot contain consecutive . characters (e.g., "a..b").

  3. The key name must be unique and cannot be ambiguous (e.g., {"a": 1, "a": 2} or {"a": {"b": 1}, "a.b": 2}).

  4. ISODate is used as a the date format (e.g., "date": { "$date" : "2018-08-31T17:30:00.882Z" }).

  5. When using the Insert conflict processing mode, a single file may not have duplicate _id fields or have _id fields identical to those of existing records in the database.

  6. The first row is used for all key names of imported CSV data by default. The remaining rows contain key-value records corresponding to the key names in the first row.

Currently, Insert and Upsert conflict processing modes are provided. Insert always inserts a new record when you import. Upsert determines if the record exists and, if it exists, the record is updated, otherwise a new record is inserted.

When the import is complete, you can see the record in the prompt message.

Database

点击咨询小助手