Skip to content

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). Attach a new Atlas database.
  • Your Atlas connection string is incorrect. Check here.

MongoDB paused

  • If you haven't been using Nightscout for a while and it was working before, check your MongoDB Atlas database didn't go to sleep mode. If it did, select Resume to restart it. Once done, continue below with Heroku restart all dynos.

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 many useless items in your accounts. At this point, you could benefit doing some cleanup in order to identify the correct Atlas database you want to connect to. Consider cleanup before continuing.

a) Go to your MongDB account. Log in if necessary

b) Click Connect below your cluster name (in the example below Cluster0, but it might have another name)

c) Click Connect your application

d) A new view opens, in (2) Add your connection string into your application code you will find your MONGODB_URI or MONGO_CONNECTION string.

Click Copy then Close

e) Paste it into a place where you can edit the text (i.e. a Word or a Notepad document).

Edit your string so that you add the database user password after the database user info. You defined them during your MongoDB Atlas database creation, when you reached this step.

Here’s an example of how the string is built up:

mongodb+srv:// nightscout :<password>

f) Edit your string in order to replace <password> with your database password.

g) 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).

Your string will now look like this: (do not use the same password as the example). Note there are no remaining < and >.


h) Copy this resulting string above into your Heroku variable MONGODB_URI (new Nightscout) or MONGO_CONNECTION (migration). There must be only one of these variables, not both. Open this link in another tab to see how to edit your Heroku variables.

i) If there is neither one nor the other create a new MONGODB_URI variable and paste the string in the value field.

j) If you remembered your password restart all dynos in Heroku, and you should be done.

k) If you changed your password or your Nightscout page still fails to open continue.

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

Note: take a look at the top of this view, after Edit User you can see your database user name before @. Check it's matching the one in your connection string.

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

  • Refreshing your Nightscout web page display should be enough, but you can also restart Heroku dynos.

Back to top