Meet your connection string


For technical details look here.

A typical mLab migrated string will look like this:


A typical new string created with Atlas will look like this:


  • It will start by mongodb+srv:// with mongodb a standard prefix for a connection string, and +srv adding a security layer.

  • After :// you'll find your database username, that is not your Atlas account username. In the examples above heroku_0v50k8rf or johndoe.

  • Following the username, a separator : and your database password that is not your Atlas account password. In the examples above a typical 26 characters password created automatically with the mLab add-on ddfsjcpfu8fcoj9n6dueabfd5u and a user created password V3ry53cr3t.

  • Following the password, a separator @ then the host name that was provided by Atlas after you created you cluster. typically it will look like

  • After the host name and the separator / you'll see your Nightscout database name. If you migrated from mLab it will be identical to your database username (unless you modified it). If you created your Atlas cluster it will be the one you decided. In the examples above heroku_0v50k8rf or myCGMiC.

  • Another separator ? and you'll see two options: retryWrites=true&w=majority

Unable to connect to Mongo

Common reasons:

  • The database Heroku is pointing to is not available (mLab services stopped in Dec 2020).

  • Your Atlas connection string is incorrect

If you see this message

MongoDB in read only mode

If you see this message:

  • Verify your Atlas database is not read only, if migration went well on the first time it should be like this, else click Edit

  • Change the permissions to Atlas Admin and Update User

  • Restart all dynos in Heroku


If you see this message:

  • If you forgot to migrate to Atlas you need to attach a new Atlas database.
  • If you know you migrated, and your Nightscout was still functional after November 11th 2020, continue below to recover:

Generic Unable to connect to Mongo

If you see this message:

  • Check you authorized all IPs to access your Atlas database:
  • Open your Atlas cluster and select your Nightscout project, then Network access

  • If you see an IP (in red above) instead of click Edit select ALLOW ACCESS FROM ANYWHERE then Confirm.

  • Restart all dynos in Heroku

Bad connection string

If you see this message:

  • Open Heroku and Reveal Config Vars in Settings

  • Search for a variable called MONGODB_URI or MONGO_CONNECTION. If you find none, go here.


There should be at least one and only one of them, not both.

If you migrated from mLab Heroku add-on it is usually MONGO_CONNECTION

if you deployed a brand new Nightscout it should be MONGODB_URI

  • Verify it is looking like this:


Note that your atlasusername, atlaspassword and dbname will be different from the example above.

  • Paste the string in the box below:

  • Click the Analyze button:

Analysis result will appear here.

If the analysis result doesn't show any error, check below the data is what you actually wanted:

Database Username:


Database Password:


Database name:



If you migrated from Heroku mLab add-on, your database username and database name should be identical.

If you've just created a new site, try to use this help page to verify or recreate it.

If you're still in trouble continue below:

Recover your connection string

If you've tried several times to deploy or migrate, you might end-up with too many items to cope with in your different accounts. At this point, you could benefit doing some cleanup in order to identify the correct Atlas database you want to connect to.

Cleanup and come back.

  • Log into Atlas
  • Click Connect on your cluster

  • Click Connect your application

  • Click Copy then Close

  • Paste the connection string in this box below:

  • Modify the database password and database name (not username) in the boxes below (only letters and numbers allowed). Don't use the values below: they are examples. Put those you used when creating your Atlas database.

Database password:

Database name:

If you migrated from mLab and Heroku (not Azure)

Your database name should be identical to your database user name! (Unless you modified it) "

  • If you don't remember your Atlas database password (which should not be your mongoDB Atlas account password) invent a new one (only letters and numbers). And proceed to Change your Atlas database password then come back.

The connection string will appear here

  • Copy the resulting string into your Heroku variable MONGODB_URI (new Nightscout) or MONGO_CONNECTION (migration). There must be only one of these variables, not both.
  • If there is neither one nor the other create a new MONGODB_URI variable and paste the string in the value field.
  • Restart all dynos in Heroku

Change your Atlas database password

  • If you changed the password in the string you will need to change it in the database too:

  • Click Database Access

  • At the end of the line, click Edit

  • In Password click Edit Password

  • If you forgot your password invent a new one (use only letters and numbers: no special characters) or better: use Autogenerate Secure Password and click Copy
  • Else make it the same than the one in your Heroku MONGODB_URI connection string variable

  • Click Update User

  • Make sure the password matches in your connection string Heroku variable MONGODB_URI (new Nightscout) or MONGO_CONNECTION (migration)

  • Refresh your Nightscout web page display