Thank you for participating in the MongoDB to Azure DocumentDB Migration What The Hack. Before you can start hacking, you will need to set up some prerequisites.
In this challenge, you will set up the necessary prerequisites and environment to complete the rest of the hack, including:
You will need an Azure subscription to complete this hack. If you don’t have one, get a free trial here…
You will need a set of developer tools to work with the sample application for this hack.
You can use GitHub Codespaces where we have a pre-configured development environment set up and ready to go for you, or you can setup the developer environment on your local workstation using DevContainers.
You must have a GitHub account to use GitHub Codespaces. If you do not have a GitHub account, you can Sign Up Here.
GitHub Codespaces is available for developers in every organization. All personal GitHub.com accounts include a monthly quota of free usage each month. GitHub will provide users in the Free plan 120 core hours, or 60 hours of run time on a 2 core codespace, plus 15 GB of storage each month.
You can see your balance of available codespace hours on the GitHub billing page.
The GitHub Codespace for this hack will let you run the sample MFlix application which uses MongoDB as its database.
NOTE: Make sure you do not sign in with your enterprise managed Github account.
Once you are signed in:
Dev container configuration drop down is set to xxx-mongodb-toazuredocumentdb-migrationYour Codespace environment should load in a new browser tab. It will take approximately 3-5 minutes the first time you create the codespace for it to load.
You are ready to setup the MongoDB source database. Skip to section: Setup the Source MongoDB Database
NOTE: If you close your Codespace window, or need to return to it later, you can go to GitHub Codespaces and you should find your existing Codespaces listed with a link to re-launch it.
NOTE: You can skip this section if are using GitHub Codespaces!
If you want to setup this environment on your local workstation, expand the section below and follow the requirements listed. We have provided a Dev Container that will load the development environment on your local workstation if you do not want to use GitHub Codespaces.
The Dev Container with the Mflix app is available in a Student Resources package.
Resources.zip package to your local workstation.The rest of the challenges will refer to the relative paths inside the Codespace or Resources.zip file where you can find the various resources to complete the challenges.
You will next be setting up your local workstation so that it can use Dev Containers. A Dev Container is a Docker-based environment designed to provide a consistent and reproducible development setup. The VS Code Dev Containers extension lets you easily open projects inside a containerized environment.
NOTE: On Windows, Dev Containers run in the Windows Subsystem for Linux (WSL).
On Windows and Mac OS (NOTE: only tested on Apple Silicon):
Resources.zip to your Linux home directory and unzip it there.Dev Containers: Reopen in ContainerYou can choose to deploy a MongoDB instance in Docker container in Azure Container Instances with a deployment script or if you prefer, you can set up the source database in MongoDB Atlas instead manually.
Login to the Azure CLI from the terminal in your GitHub Codespace or local workstation:
az login
NOTE: If you have access to multiple Azure subscriptions, you may need to switch to the subscription you want to work with.
If you are using GitHub Codespaces, the az login command will use a Device Code to login. If your organization’s Azure policy prevents this, follow these steps first before you run the deployment:
CODESPACES=false
az login
Perform the following steps to create an instance of MongoDB in your Azure subscription
Type the following commands to deploy MongoDB in a container
cd infra
chmod +x deploy-source-db.sh
./deploy-source-db.sh --administratorLogin mflixadmin --administratorPassword <password>
Optional: If you need to, you can specify the resourceGroupName and location as arguments to the deploy-target-db.sh script as follows. Note: It defaults to rg-mflix-documentdb and eastus2 for those, respectively:
cd infra
chmod +x deploy-source-db.sh
./deploy-source-db.sh --resourceGroupName <your_resource_group_name> --location westus --administratorLogin mflixadmin --administratorPassword <password>
If you want to deploy to MongoDB Atlas instead, go to this link: Get Started With Atlas.
.env file with your MongoDB connection string from Atlas.The sample MFlix application is implemented as a Node.js application. You will be running this application either within your GitHub Codespace or Dev Container for simplicity. In practice, it would be deployed as a container into Azure.
In a Terminal session in VSCode, navigate to the MFlix folder and run the application:
# Starts up the MFlix web application
npm start
You should see a message in Visual Studio Code that your Application running on port 5001 is available. Click the Open in Browser button to open the MFlix application. Try it out!
Note: If you need the username and password you chose during the MongoDB deployment, they are stored in the MFlix/.env file in the MFLIX_DB_URI connection string.
To complete this challenge successfully, you should: