What is this all about?
In November 2020, mLab will be shut down. The database was acquired by mongoDB a while back, and serves as the database backend to Nightscout, your trusty #wearenotwaiting CGM in the cloud. Luckily, mongoDB provides an easy “migration” to its Atlas database, which works as well and is, in the same configuration, also free. All it takes is about ten to fifteen minutes of time, a web browser, some kind of digital notepad (something to paste things into), and very little else. You can do it, even if it sounds scary right now. Trust me.
Step 1: A little provisioning and pre-work
First, we’ll need to log into Heroku and do some work. Please make sure to remain logged into your Heroku dashboard for the remainder of this tutorial and do all other work in tabs in the same browser. This will make logging into and out of things much easier.
If you’ve forgotten your Heroku password, reset it with the link, then log in and go into “Settings” in the Dashboard after selecting your app.
Here scroll down until you find “Reveal Config Vars.” Open this and scroll down until you find “MONGODB_URI”, “MONGOLAB_URI” or “MONGOLAB_<color>_URI” The variable should be similar to
"mongodb://<username>:<password>@<something>.mlab.com:<blah>/<blah>”. Copy this variable (not the name, the data above) and create a new variable at the bottom of the list called
MONGO_CONNECTION. Paste the copied data from the previous copy into this.
That’s all we need to do here because Nightscout already looks for a variable named
MONGO_CONNECTION to use.
Hint: I keep a notepad open on my computer (I am using Drafts) and paste all this into it. Makes it much easier, later, even with a clipboard manager.
Step 2: Create an Atlas Account
Go to https://www.mongodb.com/cloud/atlas and create an account. After the account is created, it will ask you to create an organisation (do this), a project (this, too) and a “Cluster.” Skip the cluster creation.
On top of your mongoDB screen, select the organization you just created, and click the green gear icon next to it. This will take you to the settings page.
Open a new tab. Go to https://mlab.com/login/ and use the username from your connect string you pasted above. (
mongodb://<username>:<password>). Try the password. If it does not work, ask to be sent a password reset link and reset the password to the password in
Log in and stay logged in. Now return to the tab with your Atlas settings.
Step 3: Connect mLab to Atlas
Make sure the mLab tab is still open in the background, then click on “Connect to mLab.” It should ask you to authorise the connection, which you should accept.
Once this is done, you should be back on the Atlas page. Find the “green leaf” Icon (it’s to the left of the gear you clicked a little earlier). Click it and find “mLab Account” in the left navigation pane. Click it.
You should see one or more “projects.” It’s very likely just one, if not then find the one that sounds like the data you just used (username). There are ellipses at the end of the project’s line, click them.
Click “Configure Migration”
Step 4: Migrate (we’re almost done)
A “checklist” of sorts is being displayed. Before you are going through it, you’ll have to turn off Nightscout for a bit. That’s to ensure that no new data is being written into the database as you migrate. Simply go back to your Heroku settings page, scroll down, and move the switch for “Maintenance Mode” to on.
Click each of them in order.
Target Project – accept the defaults.
Database Users – just accept the defaults. Input the old username/password if they’re empty.
IP Whitelist – accept the “allow all” option.
Target Cluster – accept the recommended default (“Create most equivalent…”). If the system complains, that you already have a free project open Atlas in a new tab and delete the “Cluster 0” you might have created at account creation. This can take a minute or three. It will also take a while for the system to create the new cluster.
Confirm – accept the defaults.
Test Migration – test the migration, this works by itself. Just let it run. If errors happen, which is very rare, the system explains how to fix them.
Test Connectivity – Skip this. Next to “confirm and continue” is a dropdown arrow. Select it and select “skip.” To test connectivity you’d have to log into a Heroku shell, which isn’t worth the effort of setup. HOWEVER: there is a connection string displayed. Something like this:
Click on “Copy” and paste this into your Notepad or somewhere else.
Migrate – this steps puts the meat on the grill: click it and be prepared to wait a few minutes.
Step 5: Adjust config variable
Head back to your Heroku tab. Here you will need to head down to the
MONGO_CONNECTION variable and paste the one you copied in the Test Connectivity step. Make sure that username and password are set to the old ones. To edit a config variable click on the pen icon.
Step 6: The scary step, letting go
You are migrated. Time to say good bye to mLab and delete it. On Heroku’s interface simply click “delete” and you’re done. This will also delete your old “MONGODB_URI”, “MONGOLAB_URI” or “MONGOLAB_<color>_URI” variable, so make sure you did Step 5 or at least copied the data somewhere safe (your notepad).
Welcome to the future
You are done and migrated. Welcome to the future. Wasn’t so scary, now, was it?