Skip to content

Attach a new Atlas database to your Heroku app


In December 2020, mLab stopped operations.

If you were using Heroku DIY and didn't migrate your database from mLab to Atlas you need to create a new database for your Nightscout site.

If you prefer to follow a video

Use this easy guide. Make sure to use only letters and numbers in database name and password.

Step 1: Create an Atlas account


MongoDB Atlas regularly changes the site aspect. If you encounter a page not matching this documentation search for keywords like not now, skip or later to continue. Report discrepancies here.

  • MongoDB Atlas will send you an email, if you don't receive it check your Spam folder.

  • In the email you received from MongoDB Atlas (mongodb-atlas @, click on Verify email

  • Another browser tab will open with your confirmed MongoDB account, Continue.

  • Enter some information (like below) and click Finish.

  • Select Create a cluster in Shared Clusters (FREE)

If you ever see this, just STOP

We're building a free cluster: you don't need to provide any billing information.

  • Check you selected Shared, leave all default values and click Create Cluster

  • Select Username and Password and invent a database username (for example nightscout) and a database password (for example soo5ecret but please make one that's yours!).

Database credentials: Do not use your Atlas account credentials. Do not use special characters: only letters and numbers. No spaces.

  • Write down these credentials in the lines below (yes, in this browser window you're reading now, unless you're reading a printed version). You’ll need them later.

Database password (write here ->)

Database username (write here ->)

  • Then click Create User.

  • Select My Local Environment and in the box My IP address write (mind these are all zeroes, not the letter O)

If you don't allow access from anywhere (IP Nightscout will not be able to access your database.

  • Then click Add Entry.

  • Click on Finish and Close

  • Click on Go to Databases

  • Atlas will create your default cluster, it can take more than 3 minutes

  • Click on CONNECT

  • Click on Choose a connection method

  • Select Connect your application

  • Copy the connection string: click Copy and paste it somewhere to edit it (like Notepad).

  • Paste the string in the line below (yes, in this browser window you're reading now, unless you're reading a printed version).

(paste here ->)

It should be similar to this (xxxxx will be different):


  • Invent a name for your database, this is not a critical information (for example mycgmic), note that default is myFirstDatabase. Only letters and numbers, no spaces.

Database Name (write here ->)

  • Click on the word Generate (just here below this line: in this browser window you're reading):

The connection string will appear here


Keep this string safely aside, it is called your MONGODB_URI

  • If you want to do it manually: replace <password> with your database password as noted previously (in the example below soo5ecret) and <dbname> by any text you want, say mycgmic for example. The result will be like this:



There are no < and > characters in the final string, neither for password nor for database name.

Step 2: Add your connection string to Heroku

Access your variables opening Heroku.


Salesforce requires two-factor-authentication for more Heroku security, this is mandatory starting Feb 2022. For an overview of possible methods see here.

  • Select your app

  • Click Settings

  • Scroll down and click Reveal Config Vars

  • Scroll down Config Vars until you’ll see KEY and VALUE

  • In KEY write MONGODB_URI and paste in the field VALUE the connection string you obtained above from Atlas. Click Add

  • This new key will be inserted at the bottom of the list.

Step 3: Update Nightscout

Update your Nightscout to latest release!

Versions older than 13.0.x won't probably run.

Versions 13.x are not optimized for the Atlas database.

Check your profile time zone is correct.

Back to top