Documentdb — Mongorestore

mongorestore --host <documentdb-cluster-endpoint> \ --port 27017 \ --username <username> \ --password <password> \ --authenticationDatabase admin \ --ssl \ --sslAllowInvalidHostnames \ --db target_db \ /path/to/backup/dump

Migrating data to using mongorestore is the most common "offline" migration path for MongoDB-compatible workloads. Because DocumentDB is a fully managed service that separates compute from storage, using mongorestore effectively requires understanding specific connection requirements, compatibility flags, and performance tuning. 1. Prerequisites for DocumentDB Restoration

Run the mongorestore command, specifying the DocumentDB connection string, database name, and collection name: mongorestore documentdb

mongorestore --uri="mongodb://<DocumentDB_account_name>:<password>@<DocumentDB_account_name>.documents.azure.com:10255/" --db <database_name> --collection <collection_name> --archive dump.gz --gzip

DocumentDB’s write throughput is governed by instance size (e.g., R4, R5, T3). To avoid overwhelming the cluster: mongorestore is best suited for one-time migrations, smaller

mongodump --uri="mongodb+srv://source-cluster" --gzip --out=./backup mongorestore --host docdb-2023-xxxxx.cluster-xyz.us-east-1.docdb.amazonaws.com:27017 \ --ssl --sslAllowInvalidHostnames \ --username admin --password secure123 \ --authenticationDatabase admin \ --numInsertionWorkers 8 --batchSize 500 \ --gzip \ --nsInclude "myapp.*" \ ./backup

For continuous backup and point-in-time recovery, DocumentDB provides native automated snapshots. For cross-region replication, use global clusters. mongorestore is best suited for one-time migrations, smaller datasets (< 1 TB), or restoring from local MongoDB dumps. For huge datasets (multi-TB), consider AWS Database Migration Service (DMS) with parallel full-load tasks. DocumentDB supports it

Use --drop carefully. DocumentDB supports it, but if you drop a large collection, the cluster may take time to reclaim storage. Prefer restoring into a new database when possible.

mongorestore \ --host :27017 \ --ssl \ --sslCAFile global-bundle.pem \ --username \ --password \ --db \ --dir \ --numInsertionWorkersPerCollection 4 Use code with caution. Copied to clipboard Performance & Best Practices