mongodump(1)
Export data from a MongoDB instance to BSON or JSON format for backup or migration purposes.
Synopsis
mongodump [options] [--uri connectionString]Description
mongodump is a utility for creating a binary export of the contents of a MongoDB database. It produces BSON files by default, which can be restored using mongorestore. This is the standard backup method for MongoDB and preserves all data types and structure.
mongodump can export entire instances, specific databases, or individual collections. It connects to a running MongoDB server and reads data without blocking normal database operations, making it suitable for live backups.
Common options
| Flag | What it does |
|---|---|
--uri | MongoDB connection string (e.g., mongodb://user:pass@host:27017/database) |
-h, --host | MongoDB server hostname or IP address (default: localhost) |
-p, --port | MongoDB server port (default: 27017) |
-d, --db | Dump a specific database; omit to dump all databases |
-c, --collection | Dump a specific collection (requires --db) |
-o, --out | Output directory for dump files (default: ./dump) |
-u, --username | Username for authentication |
-p, --password | Password for authentication (prompt if omitted) |
--authenticationDatabase | Database to authenticate against (default: admin) |
-q, --query | JSON query to filter documents during export |
--gzip | Compress output files with gzip |
--numParallelCollections | Number of collections to dump in parallel (default: 4) |
Examples
Dump entire MongoDB instance to timestamped directory
mongodump --out /backup/mongo-$(date +%Y%m%d)Backup a single database to a directory
mongodump --db myappdb --out /backup/myappExport only active users from the users collection
mongodump --db myappdb --collection users -q '{"status": "active"}' --out /backupBackup remote MongoDB with authentication (prompts for password)
mongodump --host mongodb.example.com --port 27017 -u admin -p --authenticationDatabase admin --out /backupBackup MongoDB Atlas cloud instance using connection string
mongodump --uri 'mongodb+srv://user:[email protected]/dbname' --out /backupCreate compressed backup of database (reduces storage size)
mongodump --db myappdb --gzip --out /backup/compressedDump specific collection with increased parallelism for faster backup
mongodump --db myappdb --collection logs --numParallelCollections 8 --out /backup