$linuxjunkies
>

mongodump(1)

Export data from a MongoDB instance to BSON or JSON format for backup or migration purposes.

UbuntuDebianFedoraArch

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

FlagWhat it does
--uriMongoDB connection string (e.g., mongodb://user:pass@host:27017/database)
-h, --hostMongoDB server hostname or IP address (default: localhost)
-p, --portMongoDB server port (default: 27017)
-d, --dbDump a specific database; omit to dump all databases
-c, --collectionDump a specific collection (requires --db)
-o, --outOutput directory for dump files (default: ./dump)
-u, --usernameUsername for authentication
-p, --passwordPassword for authentication (prompt if omitted)
--authenticationDatabaseDatabase to authenticate against (default: admin)
-q, --queryJSON query to filter documents during export
--gzipCompress output files with gzip
--numParallelCollectionsNumber 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/myapp

Export only active users from the users collection

mongodump --db myappdb --collection users -q '{"status": "active"}' --out /backup

Backup remote MongoDB with authentication (prompts for password)

mongodump --host mongodb.example.com --port 27017 -u admin -p --authenticationDatabase admin --out /backup

Backup MongoDB Atlas cloud instance using connection string

mongodump --uri 'mongodb+srv://user:[email protected]/dbname' --out /backup

Create compressed backup of database (reduces storage size)

mongodump --db myappdb --gzip --out /backup/compressed

Dump specific collection with increased parallelism for faster backup

mongodump --db myappdb --collection logs --numParallelCollections 8 --out /backup

Related commands