Fastest way to migrate database from mLab to MongoDB Atlas

Shahnawaz Haque
3 min readDec 5, 2020

mLab was a powerful cloud DB platform offering ready to go mongo DB for production and non-production usage. It was one of the earlier cloud DB platform with option for free DB. However, it is retiring its DB infrastructure on 8th December 2020 and requesting users to migration to MongoDB Altas wherein you have to setup your own DB cluster with the option to choose the background cloud infrastructure. mLab is offering a migration tool to complete this change. You can read more here. While going through the documentation you might find it difficult to complete the migration using the tool and initial setup required. Here is a quick alternative fastest way to migrate to MongoDB Atlas.

Note: This will change the DB connection string to a new one which is used n application. Using the migration tool it will remain as it is. More here — https://docs.mlab.com/how-to-migrate-to-atlas/#using-mongodump-mongorestore

Step 1 -> Take mongo DB dump from mLab

Example — mongodump -h ds225840.mlab.com:25840 -d <dbname> -u <username> -p <password> -o ~/Documents/dbdump

This will create a folder within dbdump with your database name.

Step 2 -> Setup an Atlas Account

Open https://cloud.mongodb.com/ and signup with your google account or a work email id.

Create a project under an organisation. You can use it to segregate different projects. Atlas will create a default one for youand you can skip it if required.

Setup a cluster.Just click on “Create a New cluster”. It will spin up a server with MongoDB installed allowing you to create DBs. Default DBs will be setup.

Create a New Cluster

Step 3-> User Account

Setup a user account for access to the DB.You can find it under Security

Database User

Step 4-> Network Access

To access the DB you can choose to restrict access to specific servers/machines or allow access from any system. For this you setup the access which can be done from this screen

Network Access

Step 5->Database creation to restore your DB

Create a DB on the new cluster by creating a dummy collection. For example create a collection with name “test” and give a name to your database.You can do this from the below options

Connect to DB

Step 6-> Restore the DB

In order to setup the database with earlier database you need to restore it from dump taken in Step 1.

Get the connection URL for your database from the below screen. I am connecting from terminal and have mongodb installed on my system. You can also connect to this db using MongoDB Compass (A GUI for MongoDB)

mongorestore — uri mongodb+srv://<user>:<Password>@cluster0.73bc4.mongodb.net -d <dbname> ~/Documents/dbdump/<dbname>

This completes the data migration and you can access your old mLab database from MongoDB Altas on a new URI and configure your application as required.

That’s it folks. Hope this makes the migration task much easier.

--

--

Shahnawaz Haque

Consulting in Retail & Logistics. Exploring ML and Blockchain based products. Loves to read books and hunt new products