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:
- An Azure subscription. If you don't have one, create a free account before you start.
- The Azure portal accessible via a web browser.
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:
- Sign in to the Azure portal.
- Select Create a resource from the Azure portal menu.
- In the Search bar, type
Azure Cosmos DBand select it from the search results. - On the Azure Cosmos DB page, select Create.
- 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.
- 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.
- Select Review + create.
- 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.
- Once the Azure Cosmos DB account is created, go to the resource.
- In the left-hand menu of your Azure Cosmos DB account, select Data Explorer.
- In Data Explorer, select New Container.
- 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
400RU/s. You can change this later if needed.
- Database name: Enter a name for your database (e.g.,
- Select OK.
Step 3: Add sample data
You can add sample data to your container directly from the Azure portal.
- In Data Explorer, expand your database and select the
Itemscontainer. - Select Items from the left pane.
- Select New Item.
- Paste the following JSON into the editor:
{ "id": "0001", "category": "personal", "name": "groceries", "description": "milk, eggs, bread", "isComplete": false } - Select Save.
- 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.
- In Data Explorer, select the
Itemscontainer. - Select Explore Items.
- In the query editor, enter the following SQL query:
SELECT * FROM c WHERE c.category = "personal" - 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.