Databases in Azure Cosmos DB
A database in Azure Cosmos DB is a logical namespace that contains a set of containers. Think of it as a top-level resource for organizing your data.
Key Information: Databases in Azure Cosmos DB are regional resources. When you create a database, it resides within a specific Azure region.
Creating a Database
You can create a database using the Azure portal, Azure CLI, Azure PowerShell, or the Azure Cosmos DB SDKs.
Using the Azure Portal
- Navigate to your Azure Cosmos DB account in the Azure portal.
- In the left-hand navigation pane, select Create container.
- Under Database, select Create new.
- Enter a name for your new database.
- Click OK.
Using Azure CLI
The following command creates a new database named myDatabase:
az cosmosdb sql database create --account-name MyCosmosDbAccount --resource-group MyResourceGroup --name myDatabase
Database Operations
Common operations on databases include:
- Creating: As described above.
- Listing: Retrieve a list of all databases within an Azure Cosmos DB account.
- Reading: Get metadata for a specific database.
- Deleting: Remove a database and all its contained resources (containers, items, etc.).
Tip: Deleting a database is a permanent operation and cannot be undone. All data within the database will be lost.
Database Properties
Each database has a unique name within the Azure Cosmos DB account. The database name is case-insensitive.
Throughput Provisioning
You can provision throughput at the database level. This allows all containers within that database to share the provisioned throughput. This is known as database-level throughput.
Note: While database-level throughput can simplify management, consider container-level throughput for more granular control and predictable performance for individual containers.
Next Steps
Now that you understand databases, explore other core concepts: