MongoDB to Atlas Migration

Are you currently using MongoDB as your database, but finding it difficult to manage and scale? It may be time to consider migrating to MongoDB Atlas, a fully-managed cloud database service that provides increased flexibility, scalability, and security. In this blog post, I will walk you through the steps and commands required for a successful MongoDB to Atlas Migration from local MongoDB to MongoDB Atlas.

Prerequisites

Atlas Migration Steps

1. Database dump from the local MongoDB server

To dump the data we need to use the mongodump command. See the example below:

mongodump --host localhost --port 27017 -u admin

In the above command, localhost is the host where the local MongoDB server is running. Port is used default for MongoDB. If you have a different port you can use that port. And admin is the MongoDB database user for your local server.

After executing the above command it will prompt for a password. Make sure to input the correct password for the user admin to dump successfully.

This step should export all the databases in the dump directory.

2. Restore to Atlas cluster

Now, you can use mongorestore command to restore the data from your local machine to the Atlas cluster.

The command is given below:

mongorestore --uri "mongodb+srv://your_cluster_username:your_cluster_password@your.atlas.mongodb.net"

The above command will restore all the data to the Atlas cluster if the credentials and URL are correct.

Important

Make sure you change the correct values for your_cluster_username, your_cluster_password, and your.atlas.mongodb.net in the command above.

Conclusion

By following the steps given above you should be able to migrate data from your local machine to the Atlas cluster.

Sharing Is Caring:
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments