
Migrate MongoDB Atlas to Self-Hosted VPS: Complete Data Migration Guide
Step-by-step guide to migrate your MongoDB database from Atlas to a self-hosted VPS using mongodump and mongorestore. Includes data verification and rollback strategies.
Published on: Friday, Jan 9, 2026
Ready to move your MongoDB database from Atlas to a self-hosted VPS? This guide covers the complete migration process using mongodump and mongorestore—the official MongoDB tools for safe, reliable data transfer.
Prerequisites
Before starting the migration, ensure you have:
- A running MongoDB instance on your VPS (see our MongoDB installation guide)
- MongoDB Database Tools installed on your local machine
- Your MongoDB Atlas connection string
- Your VPS MongoDB connection string
Step 1: Install MongoDB Database Tools
The migration tools (mongodump, mongorestore) are part of MongoDB Database Tools. Install them on your local machine:
Step 2: Export Data from MongoDB Atlas
Use mongodump to create a backup of your Atlas database. This is a non-destructive operation—your Atlas data remains untouched.
Step 3: Verify the Backup
Always verify your backup before proceeding. Check the backup directory structure and file sizes:
You should see .bson files for each collection and corresponding .metadata.json files containing indexes.
Step 4: Transfer Backup to VPS
Copy the backup files to your VPS using SCP:
Step 5: Import Data to VPS MongoDB
SSH into your VPS and restore the database using mongorestore:
If you used --gzip during export, add --gzip to the restore command as well.
Step 6: Validate the Migration
Critical: Always validate your data after migration. Connect to your VPS MongoDB and verify:
Compare document counts with your Atlas database to ensure nothing was lost.
Step 7: Update Application Connection String
Update your application's environment variables to point to the new VPS MongoDB:
Rollback Strategy
Keep your Atlas database running until you've fully validated the migration. If issues arise:
- Revert your application's connection string to Atlas
- Investigate and fix issues on VPS
- Re-run migration with fresh data if needed
- Only decommission Atlas after a week of stable production
Migration Tips
- Test on dev first — Always migrate a development database before touching production
- Schedule during low traffic — Minimize data changes during migration window
- Document everything — Keep notes of each step for troubleshooting
- Set up monitoring — Monitor VPS MongoDB performance after migration
FAQs
Q: How long does migration take?
A: Depends on database size and network speed. A 15MB database takes under a minute. Larger databases (1GB+) may take 10-30 minutes.
Q: Will indexes be preserved?
A: Yes, mongodump exports index definitions in .metadata.json files, and mongorestore recreates them automatically.
Q: Can I migrate while the application is running?
A: Yes, mongodump creates a point-in-time snapshot. However, any writes after the dump starts won't be included. For zero-downtime migration, consider MongoDB's live migration tools or a brief maintenance window.
Q: What if mongorestore fails midway?
A: mongorestore is idempotent. Drop the partially restored database and run it again. Your backup files remain intact.
Conclusion
Migrating from MongoDB Atlas to a self-hosted VPS is straightforward with mongodump and mongorestore. The key steps: export your data, transfer securely, import to VPS, and validate thoroughly. Keep Atlas running as a fallback until you're confident in the migration.
Stay Updated
Get the latest updates and insights directly to your inbox.




