Introduction
A backup is not a restore. We've seen production incidents where teams had pristine backups but couldn't recover the data they needed because they'd never actually tested the restore process. Backups for MongoDB: a practical MongoDB & NoSQL guide starts with one fundamental principle: backups only matter if you can retrieve what you've lost, exactly when you need it, and ideally at the exact point in time before something went wrong. In this article, we'll walk through the backup and restore strategies that work at scale, from managed Atlas snapshots to point-in-time recovery, and how to build a testing cadence that keeps your team confident.
Atlas Continuous Backups
If you're running MongoDB on Atlas, continuous backups are enabled by default on most clusters. Atlas maintains a 7-day rolling window of backup snapshots and oplog data, allowing you to restore to any point within that window. This is fundamentally different from the old binary backup model—you're not just getting discrete snapshots; you're getting a continuous stream of oplog entries that let you replay data changes down to the second.
Here's how it works in practice: Atlas takes automatic snapshots every 6 hours (or every hour on higher-tier clusters) and keeps a copy of your oplog. If someone accidentally deletes a collection at 14:32 UTC, you can restore to 14:31:45 UTC and skip the deletion entirely.
To set this up, navigate to your Atlas cluster's Backup tab and enable continuous backups if not already active. You'll see a timeline showing available restore points. In your application code, you don't directly interact with this—the restore happens at the MongoDB operation level.
The cost is built into Atlas billing, and the storage overhead is modest compared to the risk you're mitigating. For development environments, you can disable continuous backups to save cost; for production, it's non-negotiable.
mongodump for Small Databases
For smaller databases, or for scenarios where you need full logical backups that are portable and human-readable in JSON form, mongodump is still the standard tool. mongodump reads collections and writes them as BSON files (or JSON with the --archive flag), creating a complete, offline copy you can move between environments or store long-term.
A typical workflow looks like this:
// Schedule this as a daily cron job
mongodump --uri "mongodb+srv://user:password@cluster.mongodb.net/production" \
--out /backups/mongo-dump-$(date +%Y%m%d-%H%M%S) \
--gzip \
--numParallelCollections 4
The --gzip flag compresses the output significantly, and --numParallelCollections parallelizes the dump across multiple collections, speeding up large backups. On a 50GB database, this might take 10–15 minutes depending on your network and disk I/O.
To restore from a mongodump backup:
mongorestore --uri "mongodb+srv://user:password@cluster.mongodb.net/recovery" \
--dir /backups/mongo-dump-20250219-143022 \
--gzip \
--numParallelCollections 4
The restore will create the database and collections if they don't exist and insert all documents. Indexes are also restored.
mongodump has limitations: it can lock resources on very large deployments (use --snapshot on filesystem snapshots if available), and it's slower than Atlas snapshots. But for databases under a few hundred GB, or for ad-hoc backups before a migration or schema change, it's invaluable. Many teams keep both: Atlas continuous backups for RTO/RPO needs, and mongodump for long-term archives and cross-region portability.
Test Restores Regularly
This is where most teams fail. A backup that's never been restored is just insurance you haven't cashed. We recommend a monthly restore test on a non-production database, ideally in a separate AWS region or cloud account.
Here's a practical testing plan:
- Monthly full restore: Pick a random backup snapshot from Atlas or a mongodump archive. Restore it to a staging cluster. Verify collections exist, document counts match, and indexes are present.
- Quarterly data validation: Run aggregation queries on the restored data against known results. For example, if your production users collection has 50,000 documents with an average age of 34, verify those numbers match in the restore.
- Annual failover drill: Simulate a complete region failure by promoting a read replica or restoring to a new cluster, then running your application against it for an hour. This surfaces network config issues, authentication problems, and code bugs you'd miss in a dry-run.
Document the results. If a restore takes 4 hours and your RTO (Recovery Time Objective) is 2 hours, you now know you need a different strategy—maybe a hot standby or smaller dataset.
Many teams automate this with a Lambda function or Kubernetes CronJob that triggers a monthly restore, runs validation queries, and sends a pass/fail report to Slack. The investment in automation pays for itself the first time a real incident happens.
Point-in-Time Recovery for Critical Data
Point-in-time recovery (PITR) is your safety net for logical errors. An accidental update or delete that affects thousands of rows doesn't require a full cluster restore—you replay the oplog up to the second before the bad query ran, restore the affected documents, and redeploy.
Atlas supports PITR out of the box on continuous backups. The oplog is a capped collection that records every write operation, and Atlas keeps this for 7 days (24 hours on lower tiers). When you restore via the Atlas UI, you select a specific timestamp, and Atlas reconstructs the cluster state at that moment.
Here's a concrete example: your analytics team runs an update at 15:47:23 UTC that accidentally wipes the revenue field on 10,000 orders. You notice at 15:48:00. Instead of a full restore, you:
- Clone your production cluster from a backup snapshot taken at 15:45:00.
- Let Atlas restore oplog entries up to 15:47:20 (just before the bad query).
- Connect to the cloned cluster, query the orders with the correct revenue values.
- Use a batch update in production to fix just those 10,000 documents from your recovered data.
- Delete the clone.
This takes 20 minutes instead of 4 hours, and your users never know there was an incident.
To implement this workflow, store the timestamp of any risky operations (bulk updates, deletes, migrations) in a separate audit collection. When something goes wrong, you have a precise target for PITR rather than guessing.
// Log risky operations to an audit collection
db.auditLog.insertOne({
operation: "bulk_revenue_update",
timestamp: new Date(),
query: { revenue: { $exists: false } },
update: { revenue: calculateRevenue() },
executedBy: "analytics_job_v2.4",
estimatedAffectedDocs: 50000
});
Common Mistakes
Assuming backups are automatic and safe: Atlas backups are automatic, but they're only useful if you've tested them. Set a calendar reminder for your first restore test.
Relying solely on replication: A secondary replica doesn't protect you from logical errors—if a bad query runs on the primary, it replicates to secondaries instantly. Backups and replication are different mechanisms.
Keeping backups in the same region: If your datacenter floods, your backups flood too. Use Atlas's cross-region backup feature or periodically download mongodumps to a different cloud provider.
Ignoring oplog size: On high-write workloads, the oplog can fill up faster than the default window. Monitor rs.printOplogReplicationInfo() and size accordingly. A full oplog doesn't back up new entries.
Not documenting restore procedures: When an incident happens at 3 AM, you don't want to Google the restore commands. Write a runbook with exact steps, test it in your quarterly drill, and share it with the on-call team.
Key Takeaways
- Use Atlas continuous backups as your primary protection for MongoDB in production; they're built-in, reliable, and cost-effective.
- mongodump remains essential for small databases, ad-hoc backups, and long-term archives outside your cloud provider.
- Test restores monthly at minimum; a backup you've never restored is just data storage, not insurance.
- Point-in-time recovery with the oplog lets you fix logical errors without a full cluster restore, saving hours in an incident.
- Document your restore procedures, automate your tests, and run annual failover drills to keep your team confident under pressure.






Comments
Loading comments…