Skip to content
Latchkey

mongodump Command Reference: Flags, Usage & CI Examples

mongodump writes a binary BSON backup of MongoDB data.

mongodump connects to a MongoDB server and writes BSON files (plus metadata) for a database or collection into a directory or a single --archive file. It is the standard logical backup tool.

Common flags and usage

  • --uri="...": connection string
  • --db / --collection: limit to one database or collection
  • --out <dir>: write BSON files into a directory
  • --archive[=file]: write a single archive (file or stdout)
  • --gzip: compress the output
  • --query '{...}': dump only matching documents

Example

shell
mongodump --uri="${MONGODB_URI}" --gzip --archive=app.archive

In CI

A single --archive file must be read back with mongorestore --archive, while a directory dump restores from the directory. Admin-authenticated users need ?authSource=admin in the URI, the same as mongosh.

Key takeaways

  • mongodump produces a BSON backup as a directory or an --archive.
  • Match --archive/--gzip on dump and restore.
  • authSource=admin applies to mongodump URIs too.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →