Skip to main content

Document Database (NoSQL)

v3.0.0+

The tcb db nosql command has been available since v3.0.0.

The tcb db nosql command is used to execute native commands, export data, and restore data in the CloudBase Document Database (MongoDB).

Prerequisites

Need to first enable the Document Database service in the CloudBase console.

tcb db nosql execute

Execute MongoDB-style commands (RunCommands API).

tcb db nosql execute --command '<json>' [options]

Parameters

ParameterDescriptionRequired
-c, --command <json>MgoCommands JSON
--tag <tag>Instance Tag (used to distinguish between multiple instances in the same environment)
--instanceId <id>MongoConnector Instance ID
--databaseName <name>MongoConnector Database Name
-e, --env-id <envId>Environment ID

API documentation: RunCommands · MgoCommandParam Data Structure

Example

# Query the first 5 items of the users collection.
tcb db nosql execute \
--command '{"find": "users", "limit": 5}' \
-e my-env-id

# Execute the specified instance
tcb db nosql execute \
--command '{"count": "orders", "query": {"status": "paid"}}' \
--instanceId inst-xxx \
-e my-env-id

tcb db nosql dump

Export data from a specified collection.

tcb db nosql dump <collection> [options]

Parameters

ParameterDescriptionRequired
<collection>Name of the collection to exportYes
--file-type <fileType>Export file format: json or csv. Defaults to json.No
--fields <fields>Field names to export, separated by commas. Required when csv is selected.No
--output-dir <outputDir>Local directory to download the exported file after completion. Outputs a download URL when omitted.No
-e, --env-id <envId>Environment IDNo

After the export task completes, the CLI downloads the file to --output-dir when specified; otherwise, it outputs a download URL. With the global --json option, the output includes the job ID, job status, successful and failed record counts, and either the download URL or local file path.

Examples

# Export the users collection as JSON and output a download URL
tcb db nosql dump users -e my-env-id

# Download the orders collection JSON file to a local directory
tcb db nosql dump orders \
--file-type json \
--output-dir ./exports \
-e my-env-id

# Export selected fields as CSV and download it locally
tcb db nosql dump users \
--file-type csv \
--fields _id,name,createdAt \
--output-dir ./exports \
-e my-env-id

Notes

  • --fields is required when using --file-type csv.
  • Exported files may contain sensitive business data. Safeguard the download URL and local files, and do not commit them to source control.

Data Restoration

Data Restoration allows the Document Database to be restored to a specified historical point in time or backup snapshot.

tcb db nosql restore-time

Query the current restorable time range.

tcb db nosql restore-time [options]

tcb db nosql restore-tables

Query the list of restorable collections at the specified time point.

tcb db nosql restore-tables --time <time> [--filters <collections>] [options]
ParameterDescription
--time <time>Target restore time (e.g. 2026-03-10 14:30:00)
--filters <collections>Filter conditions, comma-separated list of collection names

tcb db nosql restore

Perform instance table restoration.

tcb db nosql restore --time <time> --tables '<json>' [options]
ParameterDescriptionRequired
--time <time>Target restore time
--tables <json>Table mapping JSON array for restoration
--instanceId <id>MongoConnector Instance ID
--databaseName <name>MongoConnector Database Name

--tables format:

[{"OldTableName": "original collection name", "NewTableName": "new collection name (restore target)"}]

tcb db nosql restore-task

Query restore task progress.

tcb db nosql restore-task [options]

Complete Restore Example

# 1. View the restorable time range
tcb db nosql restore-time -e my-env-id

# 2. View restorable collections at this time point
tcb db nosql restore-tables --time "2026-03-10 14:00:00" -e my-env-id

# 3. Perform restore (overwrite to new collection name)
tcb db nosql restore \
--time "2026-03-10 14:00:00" \
--tables '[{"OldTableName":"orders","NewTableName":"orders_restored"}]' \
-e my-env-id

# 4. Query restore task progress
tcb db nosql restore-task -e my-env-id