DEV Community

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

Posted on

1 1 1 1 1

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

Billboard image

Imagine monitoring that's actually built for developers

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay