MongoDB Backup, Restore, and Replica Set Workflows

Use mongodump, mongorestore, replica set commands, and diagnostic tools for operational MongoDB workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Backup and restore

Logical backup workflows with the MongoDB Database Tools.

Dump one database

Create a binary dump of a database.

bashANYmongodumpbackupmongodb
bash
mongodump --uri="mongodb://localhost:27017/appdb" --out=./dump

`mongodump` creates a logical BSON dump that can later be restored with `mongorestore`.

Dump one collection

Back up only a single collection.

bashANYmongodumpcollectionbackup
bash
mongodump --uri="mongodb://localhost:27017/appdb" --collection=users --out=./dump

Useful for targeted migrations or testing.

Restore a dump and drop existing data first

Restore into a collection or database after clearing prior content.

bashANYmongorestorerestoredrop
bash
mongorestore --uri="mongodb://localhost:27017/appdb" --drop ./dump

`--drop` removes existing collections before restoring them.

Restore only selected namespaces

Restore a subset of data from a larger dump.

bashANYmongorestorenamespacesrestore
bash
mongorestore --uri="mongodb://localhost:27017" --nsInclude="appdb.users" ./dump

Selective restore is useful in incident recovery and environment seeding.

Create a compressed archive dump

Stream a dump to a gzip archive.

bashANYmongodumparchivegzip
bash
mongodump --uri="mongodb://localhost:27017/appdb" --archive | gzip > appdb.archive.gz

A convenient way to produce one compressed artifact for transport or storage.

Replica set and diagnostics

Core commands for replica set awareness and quick operational checks.

Check replica set status

Inspect members, state, and health.

javascriptANYmongodbreplica-setrs.status
javascript
rs.status()

Replica sets are the basis for redundancy and high availability in production MongoDB deployments.

Initiate a simple replica set

Initialize a replica set on a self-managed deployment.

javascriptANYmongodbreplica-setrs.initiate
javascript
rs.initiate()

This is commonly used during local testing or first-time replica set setup.

Watch server metrics with mongostat

See high-level runtime activity.

bashANYmongostatmonitoringmongodb
bash
mongostat --uri="mongodb://localhost:27017"

`mongostat` provides a quick operational overview of a running deployment.

Watch read and write time with mongotop

See how much time collections spend reading and writing.

bashANYmongotopmonitoringmongodb
bash
mongotop --uri="mongodb://localhost:27017"

Useful for identifying where activity is concentrated across collections.

Recommended next

No recommendations yet.