mongodump and mongorestore Workflow
Create full and partial MongoDB backups with mongodump and restore them with mongorestore for disaster recovery and data migration.
Prerequisites
- -MongoDB installed and running
- -mongodump and mongorestore in PATH (included with MongoDB Database Tools)
Steps
Backup an entire database
Create a full binary backup of a database with compressed output.
The --gzip flag compresses individual BSON files, reducing backup size by 50-70%.
Backup a single collection
Dump only a specific collection for targeted backup or migration.
Backup with a query filter
Export only documents matching a query for selective backup.
Restore a full database backup
Restore all collections from a backup directory into the target database.
By default mongorestore inserts documents alongside existing data. Use --drop to replace existing collections.
Restore with --drop to replace existing data
Drop each collection before restoring to get an exact replica of the backup.
The --drop flag deletes all current data in each collection before restoring. Double-check the target database name.
Full Script
FAQ
Discussion
Loading comments...