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

  • Enter information then click Get Started Free

  • Select Create a cluster in Shared Clusters (FREE)

  • Leave all default values and click Create Cluster

Atlas will create your default cluster, wait until completion… (can take more than 3 minutes)

  • Click on CONNECT

  • Click on Allow Access from Anywhere

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

  • Click on Add IP Address

  • Add a database username (for example nightscout) and a database password (in the example below soo5ecret).

Database credentials

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

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

Database password:

Database username:

  • Then click Create Database User.

  • Click on Choose a connection method

  • Select Connect your application

  • Copy the connection string: click Copy.

  • Paste the string in the box below.

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.

Database Name:

  • Click the Generate button (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.

  • 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.