Note:
This is an update to blog post I did back in 2016 Azure DocumentDB and NightScout better together!
Ever since we started using NightScout more than four years ago to monitor our son’s glucose level remotely to better manage his Type 1 Diabetes condition, Microsoft Azure has been a core piece of the building blocks to host this opensource solution, from Web apps to Logic Apps to Notification Hub except the most important part backend data repository which we were using MongoLab since early days. We’ve always wanted to move to a more scalable option vs. the free sandbox offering from mlab as it was not making any sense not to use Azure and pay for paid version of mlab to avoid outages and performance issues. I heard from others in community where they opted in to host MongoDB databases themselves but ideally, we wanted to use the subscription we have had access to host not only the web app, mobile app, logic app and other pieces of the solution but also the backend data!
Early on we had conversations to change the NightScout code to port everything to Cosmos DB but that required a lot of effort till now. With MongoDB API support through Cosmos DB we now can host MongoDB databases as is while benefiting from all scalability and redundancy capabilities the service provides!
To make this real we went to couple of easy steps and in a very short time our application was backed by and running on Cosmos DB. So long MLab!!
Here are the simple steps we followed to make this happen:
- On Azure subscription provisioned a new Cosmos DB by selecting “Database as a service for MongoDB”:
- From Azure Portal got the connection string for the newly created database (Key has been changed so below key is not valid) :
- Using Studio 3T for MongoDB established a connection to both mlab and Cosmos DB instances:
- Next we provisioned an empty database in Cosmos DB and magically with a copy and paste action migrated all the collections from MLab over to Cosmos DB:
- After couple of minutes the operation was completed
- Final step was to change the connection string on NightScout Web App and just like that our open source online glocuse monitoring app was running live on Cosmos DB and Azure.
What’s Next
With this scenario and by leveraging Cosmos DB we can now leverage other Azure offerings like Machine Learning, EventGrid, Azure Functions and Logic Apps to unlock the power of data being gathered from the sensors, pumps and our artificail pancreas and to use more Azure power to better manage our son’s Type One Diabetes condition.
References: