If you are building a new NightScout site and have not started yet, go to the official NightScout instructions.

If you tried to build using the incorrect LoopDocs instruction page, or if you had a working site that died on Nov 11, 2020 because you didn’t do the Atlas migration, these instructions will help you recover and finish getting your site running.


Oh no! You ignored months of e-mails and didn’t check into the various FB groups and now your Nightscout site has died because mLab has been turned off. Well, you lost all of your old data, but you can at least make Nightscout work again. (There are other instructions elsewhere explaining how to save the data, look on Facebook if you really want to save the old data, these are the quick instructions for starting with a fresh database). Some people don’t like videos and want text instructions, or use a screen reader because of vision problems, this graphic free checklist is for them… (print it, grab a pen, use it as a checklist. Really… I will wait here while you print it, and find a pen).

These instructions will only work fully if you have upgraded your NS site to at least version 13. Otherwise, you will get a big red screen with the words “Cedar-14” at the end of this and you will need to go upgrade the NS site to get the rest of the way. Katie also has a video on how to upgrade your Nightscout site if you aren’t on 13.x or 14.x yet (click here)


Create an Atlas account.

USE CHROME, not Explorer, Edge, Safari, or any other browser, do not use private mode, do not use different windows, use tabs in the same CHROME browser window for all of these instructions. If you ignore this caution, you will be coming back later to start at the top of this document.   FireFox might work but has not been tested with these instructions.

  1. Before you start, gather the following. Nightscout site name, Heroku login, and password, a new 12 character database password that consists of numbers and letters only (I picked pizza4meandu, you should pick a different one) and an electronic scratchpad to use for editing the connection string, I used Google Docs, you can use Notepad, Wordpad, TextEdit or whatever editor you are comfortable cutting and pasting in, we will call it “scratchpad” for the rest of this document.
  2. Make sure your pen works by crossing off the first two steps on your printed document.
  3. Decide on your 12 character Atlas database password and save it into your scratchpad for later use.
  4. Go to https://www.mongodb.com/cloud/atlas in a tab in Chrome.
  5. Click the big green “Start Free” button in the middle of the page.
  6. Your company, leave EMPTY.
  7. How are you using MongoDB (response: Other)
  8. Enter an email into “Your Work Email” (if it says it is invalid, you must use a new one). It might not let you use the same e-mail you use for Heroku. It does not need to be related to work, it can be a personal email.
  9. Password 8 characters or more (I recommend using the same as Heroku).
  10. Click the Agree to Terms of Service.
  11. Click the “Get Started Free” green button. (get a new pen now if yours isn’t working well, there is a lot more to check off). If the green button didn’t work, look for a pink error box and fix what it is complaining about.
  12. If it says “This email address is already in use” pick a new one, trust me, just pick a new one.
  13. WAIT for the “Let’s get your account set up screen”, 2 seconds to 6 minutes.
  14. On the “Let’s get your account set up” screen… Scroll to the very bottom, see the tiny “Skip” letters next to the big green Continue button, Click “Skip“. Do not get distracted by any of the shiny stuff above, click “skip”. Very very bottom, you might need to scroll down to find it. Tiny letters.
  15. Look for the word “FREE”. You want the FREE cluster. Click the green “Create a cluster” button on the column that says “Shared Clusters” at the top and “FREE” at the bottom.
  16. If you are in North America, you should pick the default US option (typically us-east-1). If you are not in North America, stop and think if the option makes sense for your location. In most cases, you change NOTHING on this screen.
  17. Go to the very bottom and click the green “Create Cluster” button.
  18. WAIT. It will say “Your cluster is being created”. It can take several minutes.
  19. Get rid of the annoying “Connect to Atlas” helper that popped up on the left part of the screen by clicking “no thanks” followed by “dismiss it“. Keep WAITING while “Your cluster is being created” completes.
  20. When the screen changes and it no longer says “Your cluster is being created…” and some fancy blank graphs pop up in the middle of the screen. You are ready to continue.
  21. On the left you should see the word “SANDBOX” in a nice blue oval. Right below that is a cluster name. Below that, you should see a “CONNECT” button, click it. If you can’t click the word Connect, you probably did not wait for “Your cluster is being created” to finish.
  22. DO NOT CLICK THE GREEN BUTTON, look for “Allow Access from Anywhere” and click that. (You will get an email saying you clicked this button, ignore it like you did the three months of emails warning you of this migration).
  23. Click the green “Add IP Address“.
  24. Create a Database User. Enter ALL LOWER CASE FOR THE USER NAME AND PASSWORD. NUMBERS AND LETTERS ONLY, NAME MUST START WITH A LETTER. (ignore this part and you will fail). I recommend using the username “nsdbuser” and a 12 character password of just lower case numbers and letters. You should already have the password in your scratchpad from the steps above. Change the Database User Privileges to “Atlas Admin“. Click the green “Create Database User” button.
  25. Click the green “Chose a connection method” button.
  26. Click the middle box “Connect your application
  27. Click the “Copy” button in the middle of the screen, then paste the result to the same scratchpad that you saved the above username/password combo. The string will look similar to this “mongodb+srv://gibberish&w=majority”
  28. Click “Close” at the bottom of the box.
  29. Click on “Collections” next to where you clicked on “Connect” earlier.
  30. Click on the grey “Add My Own Data” button.
  31. Name the database name “nightscout“, and the collection name “entries“. All in lower case. Do not check the box.
  32. Click the green “Create” button.
  33. The string you saved in your scratchpad will look similar to but not exactly like this:
  34. mongodb+srv://nsdbuser:<password>@cluster0.yqukp.mongodb.net/<dbname>?retryWrites=true&w=majorityEnter the password and database names into the string in your text editor so it looks like this:
  35. mongodb+srv://nsdbuser:pizza4meandu@cluster0.yqukp. mongodb.net/nightscout?retryWrites=true&w=majority
  36. Note the part where we replaced /<dbname>? with /nightscout?, you did that part, right? You removed the greater than and less than brackets, right? You didn’t put any extra spaces in, right? If you picked a different username instead of nsdbuser, check to see if it is correct here. (I entered an extra space in the example above so it would print right for most people)
  37. You are done in Atlas. Leave it open in case you messed something up and have to go back to it, but if you did everything right, you are done with Atlas.
  38. Open a new tab in Chrome (+ button up top).
  39. Sign into Heroku. https://dashboard.heroku.com/apps
  40. Click on the project that is your Nightscout site.
  41. Click on “Settings“.
  42. Click on “Reveal Config Vars“.
  43. Scroll to the bottom of the variables to where it has a blank “KEY”, “VALUE”
  44. In the KEY field, type MONGO_CONNECTION. In the Value field, paste the big string from your scratchpad that starts with “mongodb+srv://” and ends with “w=majority” then click “Add
  45. Look for any variables that start with MONGO and are not “MONGO_COLLECTION” or “MONGO_CONNECTION” and delete them. They could have many names, some of which contain “DB”. You should end up with only TWO that start with MONGO_.
  46. If you accidentally deleted the MONGO_COLLECTION one, put it back with the word “entries” in it.
  47. Scroll to the top of Heroku and pick “More” then from the drop-down box pick “Restart all Dynos“.
  48. Go into Loop, or FreeAPS, and make a change to your ISF. Increase or decrease it by one, save it, wait 6o seconds, then change it back. This will force the profile info to be written to your new blank database. If you skip this, you will be sent to the PROFILE EDITOR when you try to launch your site, so go do it, then press refresh on your site.
  49. Within 16 minutes (don’t panic, be patient), if you entered the MONGO_CONNECTION variable correctly, you should have current information on your Nightscout site. It will first come up blank, then it will fill in with numbers after a few minutes.
  50. All done. Send an email if you found errors, post a “Yipee” on SoCalLoopers if you were successful. If you failed, read the directions again. A “Device authentication” or “API Secret” dialog box usually means you messed up the MONGO_CONNECTION variable. A frequent error is missing the end of the string “w=majority” or putting spaces in the string or at the start or end of it. A Red error box means your Nightscout software is too old, go follow the instructions to upgrade Nightscout now.
  51. Frame this document and hang it on the wall next to your participation certificate for playing T-Ball.

If you see any problems with this documentation, please click the Feedback link at the bottom of the page.  If you like these docs, post a note about it in the Loop and Learn Facebook group…

If you are totally stuck, support for Nightscout is done in the CGM in the Cloud Facebook Group. No support will be given via the Feedback Link.  The link is only for document corrections or general complaints.

Skip to content