MongoDB — Backup
mongodump
# Backup database
mongodump -d mydb -o /backup/
# Backup with auth
mongodump -u admin -p password --authenticationDatabase admin -d mydb -o /backup/
mongorestore
# Restore database
mongorestore -d mydb /backup/mydb/
# Restore with drop
mongorestore --drop -d mydb /backup/mydb/
Export
# Export to JSON
mongoexport -d mydb -c users -o users.json
# Export to CSV
mongoexport -d mydb -c users --type=csv --fields=name,email -o users.csv
Import
# Import JSON
mongoimport -d mydb -c users users.json
# Import CSV
mongoimport -d mydb -c users --type=csv --headerline users.csv
Atlas Backup
- Automatic backups
- Point-in-time recovery
- On-demand snapshots
Mini Practice
- Backup a database
- Restore from backup
- Export to JSON
- Import from JSON
Up Next
Continue with Replication — replica sets.
Related Topics
Frequently Asked Questions about Backup
What is Backup in MongoDB?
Backup is a fundamental concept in MongoDB. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Backup?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Backup.
Why is Backup important in MongoDB?
Backup is essential for MongoDB development. Understanding this concept will help you write better code and solve real-world problems more effectively.