DEV Community

Cover image for Step-by-Step Guide: Migrating Data Between MongoDB Atlas Accounts Easily
Akash Kumar
Akash Kumar

Posted on

Step-by-Step Guide: Migrating Data Between MongoDB Atlas Accounts Easily

Introduction

Migrating a MongoDB database between different hosts can be necessary for several reasons, such as moving your local database to a remote server, creating backup copies, or even pulling production data for local testing and development.

Thankfully, MongoDB offers an effortless way to handle this through mongodump and mongorestore, a powerful tool that simplifies the migration process.

Whether you're switching between MongoDB Atlas accounts or moving from a local to a cloud database, this guide will show you how to migrate your data seamlessly in just a few steps.

Step 1: Installing MongoDB Database Tools

MongoDB Database Tools are command-line utilities that help you manage and move data.

Install these tools on your platform to get started.

You can download the tool by clicking here

Image description

Step 2: Setting up Environment Variable

  • Go to the path where the MongoDB Database Tools is installed and the copy the path until the /bin as shown.

Image description

  • Then open the Environment Variables and within the User variable update the path.

Image description

  • Select "PATH", click "Edit" , click "New" => Add path which the mongodb data tools is C:\Program Files\MongoDB\Tools\100\bin and then click on Ok.

Step 3: Dump Data to a Directory

mongodump --uri "SOURCE-CONNECTION-STRING-URI"
Enter fullscreen mode Exit fullscreen mode
  • 'SOURCE-CONNECTION-STRING-URI' is URL you are using to connect your app to MongoDB -- either local something like mongodb://127.0.0.1/someDatabase or can be remote server like mongodb+srv://yourapp:<password>@cluster0.xyz123.mongodb.net/someDatabase

Image description

  • The command will save a dump of your entire database into a folder and in the directory where the command was run.

Step 4: Restore Data from Directory

mongorestore --uri "DESTINATION-CONNECTION-STRING-URI"
Enter fullscreen mode Exit fullscreen mode
  • Run the above command in the same folder where the dump was created and that's it.

Conclusion

In conclusion, this short tutorial showcased how easily data can be transferred between MongoDB instances using mongodump and mongorestore.

With these easy steps, you can quickly back up and restore your data with no hassle.

If you found this helpful, please like this post and follow for more useful tips!.

Connect with me on LinkedIn and Instagram

Top comments (0)