Quickstart: Create an Azure Cosmos DB account and database

This quickstart guides you through the process of creating an Azure Cosmos DB account, database, and container using the Azure portal.

Note: Azure Cosmos DB is a globally distributed, multi-model database service that enables you to create highly scalable and high-performance applications.

Prerequisites

Before you begin, you need an Azure subscription. If you don't have one, create a free account.

You can also use an existing Azure account.

Step 1: Create an Azure Cosmos DB account

1

Sign in to the Azure portal.

2

In the Azure portal, search for and select Azure Cosmos DB.

3

On the Azure Cosmos DB page, select Create.

Azure Portal Create Cosmos DB
4

On the Create Azure Cosmos DB page, fill in the following details:

  • Subscription: Select your Azure subscription.
  • Resource group: Select an existing resource group or create a new one (e.g., myResourceGroup).
  • Account name: Enter a globally unique name for your Azure Cosmos DB account (e.g., mycosmosdbaccount123).
  • API: Choose Core (SQL). This is the default API and most common for new applications.
  • Location: Select an Azure region close to your users.
For production workloads, consider the Capacity mode and Replication options. For this quickstart, the default settings are sufficient.
5

Select Review + create, and then select Create.

Account creation can take a few minutes.

Step 2: Create a database and container

1

Once the deployment is complete, navigate to your Azure Cosmos DB account resource in the Azure portal.

2

In the left navigation pane of your Azure Cosmos DB account, select Data Explorer.

Cosmos DB Data Explorer
3

In Data Explorer, select New Container.

The New Container pane opens on the right.

4

Fill in the New Container details:

  • Database ID: Select Create new and enter a name for your database (e.g., ToDoList).
  • Container ID: Enter a name for your container (e.g., Items).
  • Partition key: Enter /category. A partition key is required for distributing data across logical partitions.
  • Throughput: Leave the default (Manual, 400 RU/s) or choose Autoscale for dynamic scaling.
Choosing an appropriate partition key is crucial for performance and scalability. Ensure it has high cardinality.
5

Select OK to create the database and container.

Step 3: Add sample data

1

In Data Explorer, expand the ToDoList database and select the Items container.

2

Select New Item.

3

Paste the following JSON into the item editor:

{
    "id": "1",
    "category": "personal",
    "name": "groceries",
    "description": "Buy milk and eggs",
    "isComplete": false
}
4

Select Save.

5

Repeat steps 2-4 to add another item:

{
    "id": "2",
    "category": "work",
    "name": "project proposal",
    "description": "Finalize and submit the proposal",
    "isComplete": false
}

Next Steps

You have successfully created an Azure Cosmos DB account, database, and container, and added sample data. Now you can: