Quickstart: Create an Azure Cosmos DB account and a NoSQL database

In this quickstart, you'll learn how to create an Azure Cosmos DB account, a NoSQL database, and a container using the Azure portal. Azure Cosmos DB is Microsoft's globally distributed, multi-model database service. You can use Azure Cosmos DB to create highly responsive, always-available applications.

Note: This quickstart uses the Azure portal to create an Azure Cosmos DB account. For programmatic creation, see the SDK or CLI quickstarts.

Prerequisites

Before you begin, you need:

Step 1: Create an Azure Cosmos DB account

An Azure Cosmos DB account is a globally distributed, multi-model database. Follow these steps to create one:

  1. Sign in to the Azure portal.
  2. Select Create a resource from the Azure portal menu.
  3. In the Search bar, type Azure Cosmos DB and select it from the search results.
  4. On the Azure Cosmos DB page, select Create.
  5. In the Create an Azure Cosmos DB account form, select the API you want to use. For this quickstart, we'll use the Core (SQL) API.
  6. Fill in the required information for the Basic tab:
    • Subscription: Select your Azure subscription.
    • Resource group: Select or create a new resource group.
    • Account name: Enter a unique name for your Azure Cosmos DB account. This name will be globally unique and will be used as the DNS name for your account (e.g., mycosmosdbaccount.documents.azure.com).
    • Location: Select the Azure region where you want to deploy your account.
  7. Select Review + create.
  8. After validation passes, select Create. The account creation process can take a few minutes.

Step 2: Create a database and container

Now that you have an Azure Cosmos DB account, you can create a database and a container within it. A container is a set of items, and the items within a container are JSON documents.

  1. Once the Azure Cosmos DB account is created, go to the resource.
  2. In the left-hand menu of your Azure Cosmos DB account, select Data Explorer.
  3. In Data Explorer, select New Container.
  4. In the New Container form, fill in the following details:
    • Database name: Enter a name for your database (e.g., ToDoList). If the database doesn't exist, Azure Cosmos DB creates it.
    • Container name: Enter a name for your container (e.g., Items).
    • Partition key: Enter a partition key path (e.g., /category). This is crucial for performance and scalability.
    • Throughput: Choose Manual and enter 400 RU/s. You can change this later if needed.
  5. Select OK.

Step 3: Add sample data

You can add sample data to your container directly from the Azure portal.

  1. In Data Explorer, expand your database and select the Items container.
  2. Select Items from the left pane.
  3. Select New Item.
  4. Paste the following JSON into the editor:
    
    {
        "id": "0001",
        "category": "personal",
        "name": "groceries",
        "description": "milk, eggs, bread",
        "isComplete": false
    }
                        
  5. Select Save.
  6. Repeat steps 3-5 to add another item:
    
    {
        "id": "0002",
        "category": "work",
        "name": "project proposal",
        "description": "Submit Q3 project proposal",
        "isComplete": true
    }
                        

Step 4: Query the data

You can query the data in your container using the SQL query editor in Data Explorer.

  1. In Data Explorer, select the Items container.
  2. Select Explore Items.
  3. In the query editor, enter the following SQL query:
    
    SELECT * FROM c WHERE c.category = "personal"
                        
  4. Select Execute query. The results will show items where the category is "personal".

Next Steps: You have successfully created an Azure Cosmos DB account, database, and container, and added and queried data. Now you can explore more advanced topics:

Clean up resources

When you are finished with this quickstart, you can delete the Azure Cosmos DB account and its associated resources to avoid incurring further charges. You can delete the resource group containing the account.