When exporting data from a MongoDB database, you typically use the mongodump utility. Here’s how to set parameters for the export process:
Basic Command Structure:
The basic syntax is mongodump --uri="mongodb://[username:password@]host[:port]/database" --collection=collectionName --out=outputDirectory.
Common Parameters:
--uri: Specifies the connection string, including username, password, host, port, and database name.--uri="mongodb://admin:password@localhost:27017/mydb".--collection: Limits the export to a specific collection.--collection=users.--out: Defines the output directory for the dumped files.--out=/backup/mongodb.--gzip: Compresses the output files.--gzip.Authentication Parameters:
If authentication is required, include --username and --password (or use --uri for simplicity).
Example: --username=admin --password=password.
Filtering Data:
Use --query to export specific documents.
Example: --query='{ "age": { "$gt": 30 } }'.
TLS/SSL Options:
For secure connections, use --ssl and provide certificate paths if needed.
Example: --ssl --sslCAFile=/path/to/ca.pem.
Example Command:
mongodump --uri="mongodb://admin:password@localhost:27017/mydb" --collection=users --out=/backup/mongodb --gzip
For managed MongoDB services like Tencent Cloud’s TencentDB for MongoDB, you can use the Data Transmission Service (DTS) or Backup & Restore features to export data with similar parameter configurations via the console or API. Tencent Cloud also supports automated backups and cross-region replication for data export scenarios.