Attach a new Atlas database to your Heroku app

In December 2020, mLab stopped operations.

If you 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 0.0.0.0/0) 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):

mongodb+srv://nightscout:<password>@cluster0.xxxxx.mongodb.net/<dbname>?retryWrites=true&w=majority


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

The connection string will appear here


Warning

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:

mongodb+srv://nightscout:soo5ecret@cluster0.xxxxx.mongodb.net/mycgmic?retryWrites=true&w=majority

Note

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.