Get Started with Azure Cosmos DB

Your essential guide to setting up and using Azure's globally distributed, multi-model database service.

Welcome to Azure Cosmos DB: A Quick Start Guide

Azure Cosmos DB is a fully managed, globally distributed, multi-model database service that enables you to harness the benefits of horizontal scalability and low latency worldwide. This tutorial will walk you through the basic steps to get started.

Prerequisites

Before you begin, ensure you have:

Step 1: Create an Azure Cosmos DB Account

Navigate to the Azure portal and create a new Azure Cosmos DB account. You'll need to choose an API (e.g., SQL API, MongoDB API), region, and capacity settings.

Step 2: Create a Database and Container

Once your account is created, you'll need to create a database within it, and then a container (similar to a table or collection) to store your data.

Here's an example of creating a container using the Azure CLI:

az cosmosdb sql container create --account-name <your-account-name> --resource-group <your-resource-group> --name <container-name> --partition-key-path <partition-key-path>

Step 3: Add Data to Your Container

You can add data to your container using various methods, including the Azure portal, SDKs, or REST APIs. Here's a simple JSON document example:

{
    "id": "item1",
    "category": "gear",
    "name": "Olympic Torch",
    "description": "An Olympic torch, for carrying the Olympic flame",
    "isComplete": false,
    "tags": ["flame", "torch", "olympic"]
}

You can manually add this item via the Azure portal's Data Explorer.

Step 4: Query Your Data

Azure Cosmos DB supports rich querying using its various APIs. For the SQL API, you can use SQL-like queries.

Example query to retrieve all items:

SELECT * FROM c

Example query to retrieve items from a specific category:

SELECT * FROM c WHERE c.category = "gear"
Important: Understanding partition keys is crucial for performance and scalability in Azure Cosmos DB. Choose your partition key wisely based on your access patterns.

Next Steps

This tutorial covered the absolute basics. To delve deeper, explore: