Create an Angular app with Azure Cosmos DB's API for MongoDB - Create a Cosmos account
This multi-part tutorial demonstrates how to create a new app written in Node.js with Express and Angular and then connect it to your Cosmos account configured with Cosmos DB's API for MongoDB.
Part 4 of the tutorial builds on Part 3 and covers the following tasks:
- Create an Azure resource group using the Azure CLI
- Create a Cosmos account using the Azure CLI
Before starting this part of the tutorial, ensure you've completed the steps in Part 3 of the tutorial.
In this tutorial section, you can either use the Azure Cloud Shell (in your internet browser) or the Azure CLI installed locally.
Use Azure Cloud Shell
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. Cloud Shell lets you use either
PowerShell to work with Azure services. You can use the Cloud Shell pre-installed commands to run the code in this article without having to install anything on your local environment.
To launch Azure Cloud Shell:
|Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell.|
|Go to https://shell.azure.com or select the Launch Cloud Shell button to open Cloud Shell in your browser.|
|Select the Cloud Shell button on the top-right menu bar in the Azure portal.|
To run the code in this article in Azure Cloud Shell:
- Open Cloud Shell.
- Select the Copy button on a code block to copy the code.
- Paste the code into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS.
- Press Enter to run the code.
Sign in to Azure
You'll use the Azure CLI to create the resources needed to host your app in Azure. If you run Azure CLI commands in the Cloud Shell, you're already signed in. To run Azure CLI commands locally, sign in to your Azure subscription with the az login command and follow the on-screen directions.
Create a resource group
A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.
In the Cloud Shell, create a resource group with the
az group create command. The following example creates a resource group named myResourceGroup in the West Europe location. To see all supported locations for App Service in Free tier, run the
az appservice list-locations --sku FREE command.
az group create --name myResourceGroup --location "West Europe"
You generally create your resource group and the resources in a region near you.
When the command finishes, a JSON output shows you the resource group properties.
This tutorial walks you through the steps to build the application step-by-step. If you want to download the finished project, you can get the completed application from the angular-cosmosdb repo on GitHub.
Create an Azure Cosmos DB account
Create an Azure Cosmos DB account with the
az cosmosdb create command.
az cosmosdb create --name <cosmosdb-name> --resource-group myResourceGroup --kind MongoDB
<cosmosdb-name>use your own unique Azure Cosmos DB account name, the name needs to be unique across all Azure Cosmos DB account names in Azure.
--kind MongoDBsetting enables the Azure Cosmos DB to have MongoDB client connections.
It may take a minute or two for the command to complete. When it's done, the terminal window displays information about the new database.
Once the Azure Cosmos DB account has been created:
Open a new browser window and go to https://portal.azure.com
Click the Azure Cosmos DB logo on the left bar, and it shows you all the Azure Cosmos DBs you have.
Click on the Azure Cosmos DB account you just created, select the Overview tab and scroll down to view the map where the database is located.
Scroll down on the left navigation and click the Replicate data globally tab, this displays a map where you can see the different areas you can replicate into. For example, you can click Australia Southeast or Australia East and replicate your data to Australia. You can learn more about global replication in How to distribute data globally with Azure Cosmos DB. For now, let's just keep the once instance and when we want to replicate, we know how.
In this part of the tutorial, you've done the following:
- Created an Azure resource group using the Azure CLI
- Created an Azure Cosmos DB account using the Azure CLI
You can proceed to the next part of the tutorial to connect Azure Cosmos DB to your app using Mongoose.