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

Video walkthrough

Prerequisites

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 bash or 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:

Option Example/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell. Example of Try It for Azure Cloud Shell
Go to https://shell.azure.com or select the Launch Cloud Shell button to open Cloud Shell in your browser. Launch Cloud Shell in a new window
Select the Cloud Shell button on the top-right menu bar in the Azure portal. Cloud Shell button in the Azure portal

To run the code in this article in Azure Cloud Shell:

  1. Open Cloud Shell.
  2. Select the Copy button on a code block to copy the code.
  3. Paste the code into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS.
  4. 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.

az login

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.

Tip

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
  • For <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.
  • The --kind MongoDB setting 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:

  1. Open a new browser window and go to https://portal.azure.com

  2. Click the Azure Cosmos DB logo Azure Cosmos DB icon in the Azure portal on the left bar, and it shows you all the Azure Cosmos DBs you have.

  3. 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.

    New Azure Cosmos DB account in the Azure portal

  4. 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.

    New Azure Cosmos DB account in the Azure portal

Next steps

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.