How to Migrate from an Azure-hosted Mongo database

12 Feb
Guides > Labs > How to Migrate from an Azure-hosted Mongo database

This lab is specifically targeted for Nightscout users with a single website and Mongo database hosted on Azure.

There have been numerous outages with Azure-hosted Mongolab servers. Migrating your database away from Azure should reduce your Nightscout downtime. The lab will walk you through the steps to migrate your Mongo database from Azure to another provider such as Amazon or Rackspace.

In addition to simply moving your Mongo database, you can also improve your uptime by adding a second Nightscout website on Heroku or by implementing other options outlined in the redundancy lab.

To migrate your Mongo database, you will need to make the following changes

  • Clone your existing Azure-hosted Mongo database to a Mongolab server hosted by another cloud provider
  • Change your Azure website configuration to use the new Mongo URI
  • Change your uploader app configuration to use the new Mongo URI

Step 1 – Clone your existing Mongo database

  • Login to your Mongolab.com account.
  • Click the button labeled “Clone Existing” to clone your Mongo database

    Screen Shot 2015-02-12 at 12.49.54 PM

  • Choose your Mongo database from the drop down list under “Select a Mongolab Database”
  • Choose a cloud provider such as Amazon Web Services or Rackspace
  • Choose a cloud provider location close to you offering the “Single-node” plan
  • Choose the plan called “Sandbox” listed under “Single-node”
  • Enter the name of your new database
  • Click “Create new MongoDB deployment”

    Screen Shot 2015-02-12 at 12.59.43 PM 

  • Your database and collections have been migrated, however you still need to create a new database user and password. Click on your new database from the Mongolab home page. Click the link labeled “Click here” to create a database user.

    Screen Shot 2015-02-12 at 1.11.37 PM

  • In the pop-up window, enter a database username and password, and then click Create. You can use the username and password from your previous database, or create a different username and password. In either case, make sure you write the username and password down.

    Screen Shot 2015-02-12 at 1.37.16 PM

  • After creating your database user, near the top of the page you should see the text “To connect using a driver via the standard URI.” Below that text will be a generic URI for your database.

    Screen Shot 2015-02-12 at 1.21.52 PM

    You will need to write down the URI, substituting your username and password for the text <dbuser>:<dbpassword>. Based on the screen shot above, the URI would be:

    mongodb://username:password@ds043981.mongolab.com:43981/db-migration-test

Step 2 – Change your Azure website configuration to use your new database.

  • Login to the Azure Management Portal at http://manage.windowsazure.com
  • Click on your website name, then click the “Configure” button just above the graph

    Screen Shot 2015-02-12 at 1.49.40 PM 

  • Scroll down to the section called “Connection Strings” then click the link to “Show Connection Strings.”

    Screen Shot 2015-02-12 at 1.51.21 PM 

  • Find the variable called “mongo” or “MONGO_CONNECTION”. This is your Mongo URI. Copy your existing Mongo URI to a text file as backup. Change the value to the new Mongo URI for your new database created in Step 1.
  • Press the “SAVE” button at the bottom of the screen to save your website changes

    Screen Shot 2015-02-12 at 1.57.33 PM 

Step 3 – Change your Nightscout uploader app to use your new Mongo database URI.

This step is ONLY required if you are using Mongodb upload. If you are using REST API upload, you do not need to perform this step.

  • Open your Nightscout app, tap the three dots, and then tap Preferences.
  • Tap “Mongodb”, then tap “URI”

    Screenshot_2014-11-07-10-36-27-168x300  Screenshot_2014-11-07-10-39-42-1-168x300 

  • Enter your new Mongo database URI and press Ok.

    13-ns-mongo-uristring 

  • Exit out of the app preferences.
  • Disconnect your uploader phone from your Dexcom receiver.
  • Either “Force Close” the app from your phone’s Settings / Apps page, or reboot your uploader phone.
  • Reconnect your Dexcom receiver to your uploader phone.
  • Verify all uploader app icons are green, and the uploader graph shows current Dexcom data.
  • Verify your website shows current Dexcom data.

Troubleshooting

  • If your website shows a white screen after changing your website configuration, you have probably mis-typed your new Mongo URI in your Azure website configuration. Double check that A) The new Mongo URI you wrote down at the end of Step 1 (cloning your database) is correct and B) You correctly entered the new Mongo URI in your website’s “mongo” or “MONGO_CONNECTION” variable.
  • If your website shows old data but no new data, you have probably mis-typed your new Mongo URI in your uploader app. Double check that the new Mongo URI entered in your uploader app exactly matches what is entered in your website configuration.
  • If your uploader app shows a red “Upload” icon, you probably have mis-typed your new Mongo URI in your uploader app. Double check that the new Mongo URI entered in your uploader app exactly matches what is entered in your website configuration.
  • If all else fails, ask for help or revert to your previous Mongo database and URI until you have time to troubleshoot.