LinuxCommandLibrary

mongodump

creates binary exports of MongoDB databases

TLDR

Dump entire database

$ mongodump --db [database]
copy
Dump specific collection
$ mongodump --db [database] --collection [collection]
copy
Dump with authentication
$ mongodump --uri "mongodb://[user]:[pass]@[host]/[db]"
copy
Dump to specific directory
$ mongodump --out [/path/to/backup]
copy
Dump as archive file
$ mongodump --archive=[backup.archive]
copy
Dump compressed
$ mongodump --gzip --out [backup/]
copy
Dump with query filter
$ mongodump --db [db] --collection [coll] --query '{"status": "active"}'
copy
Dump from remote host
$ mongodump --host [hostname] --port [27017]
copy

SYNOPSIS

mongodump [--uri uri] [--db database] [--collection coll] [--out dir] [--archive file] [options]

DESCRIPTION

mongodump creates binary exports of MongoDB databases. It reads data directly from MongoDB and writes BSON files, preserving document structure and types.
Output format is a directory structure with one folder per database containing BSON and metadata JSON files for each collection. The archive format combines everything into a single file.
The --oplog option captures operations during the dump, enabling point-in-time restore. This is essential for consistent backups of active databases.
Query filtering exports only matching documents. This enables partial backups, test data extraction, or archiving specific records.
Compression (--gzip) significantly reduces backup size. Combined with archive format, it produces a single compressed file suitable for storage or transfer.
Parallelism options speed up large backups. Multiple collections can dump simultaneously, and documents within collections can be processed in parallel.

PARAMETERS

--uri URI

MongoDB connection URI.
--host HOST
Server hostname.
--port PORT
Server port.
--db, -d DATABASE
Database to dump.
--collection, -c COLL
Collection to dump.
--out, -o DIR
Output directory.
--archive[=FILE]
Output as archive file.
--gzip
Compress output.
--query, -q JSON
Filter documents.
--queryFile FILE
Query filter from file.
--username, -u USER
Authentication username.
--password, -p PASS
Authentication password.
--authenticationDatabase DB
Authentication database.
--oplog
Include oplog for point-in-time backup.
--dumpDbUsersAndRoles
Include users and roles.
--numParallelCollections N
Parallel collection dumps.
-j N
Parallel document dumps.

CAVEATS

Not recommended for large production databases - use filesystem snapshots instead. Backup is not atomic without --oplog. Indexes are saved as metadata, rebuilt on restore. Requires read access to all databases being dumped.

HISTORY

mongodump has been part of MongoDB since early versions, developed by MongoDB, Inc. (formerly 10gen). It provides the standard method for exporting MongoDB data, complemented by mongorestore for imports. It's part of the MongoDB Database Tools package.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community