DBAtlas · Database operations atlas

Take an archive backup with mongodump/mongorestore and restore a single collection

MongoDBBackup

Command

# Single database, one compressed archive file (password is prompted):
mongodump --uri="mongodb://admin@mongo1:27017/?authSource=admin" --db=shop --gzip --archive=/backup/shop_$(date +%F).archive.gz
# Dry run before restoring the archive under a different name:
mongorestore --uri="mongodb://admin@mongo1:27017/?authSource=admin" --gzip --archive=/backup/shop_2026-10-08.archive.gz --nsFrom="shop.*" --nsTo="shop_restore.*" --dryRun
# Restore a single collection from the archive under a new name:
mongorestore --uri="mongodb://admin@mongo1:27017/?authSource=admin" --gzip --archive=/backup/shop_2026-10-08.archive.gz --nsInclude="shop.musteri" --nsFrom="shop.*" --nsTo="shop_restore.*" --numInsertionWorkersPerCollection=4
# Restore under the same name, dropping the existing collection:
mongorestore --uri="mongodb://admin@mongo1:27017/?authSource=admin" --gzip --archive=/backup/shop_2026-10-08.archive.gz --nsInclude="shop.musteri" --drop

What it does

Backs up a database into a single gzip archive file; restores the whole database or a single collection from the archive, optionally under a different name (nsFrom/nsTo).

When to use it

For logical backups, moving data between environments or recovering a single collection that was dropped or corrupted by mistake.

Caution

mongodump is a logical backup: it is slow on large data sets and indexes are rebuilt during restore. A dump taken without --oplog is not point-in-time consistent on a live system. --drop deletes the target collection before the restore starts; restore under a different name with nsTo first and verify. The restore writes to the primary and can cause replication lag.

Open in DBAtlas →

Related