
Cloud
Learning Level
Azure Cosmos DB is a globally distributed, multi-model database that provides low latency and high availability.
By the end of this lesson, you'll understand:
# Create Cosmos DB account
az cosmosdb create \
--name mycosmosaccount \
--resource-group myResourceGroup \
--locations regionName=eastus failoverPriority=0
# Create database
az cosmosdb sql database create \
--account-name mycosmosaccount \
--resource-group myResourceGroup \
--name mydatabase
# Create container
az cosmosdb sql container create \
--account-name mycosmosaccount \
--database-name mydatabase \
--resource-group myResourceGroup \
--name users \
--partition-key-path /userId \
--throughput 400JavaScript:
const { CosmosClient } = require("@azure/cosmos");
const client = new CosmosClient({ endpoint: "https://...", key: "..." });
const database = client.database("mydatabase");
const container = database.container("users");
// Create
await container.items.create({
id: "user1",
userId: "123",
name: "Alice",
email: "alice@example.com"
});
// Read
const { resource: user } = await container.item("user1", "123").read();
// Update
await container.item("user1", "123").replace({
...user,
name: "Alice Updated"
});
// Delete
await container.item("user1", "123").delete();// Query users
const querySpec = {
query: "SELECT * FROM c WHERE c.email = @email",
parameters: [
{
name: "@email",
value: "alice@example.com"
}
]
};
const { resources } = await container.items
.query(querySpec)
.fetchAll();Learn about Azure Monitoring for performance insights, or explore containers with AKS.
Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep • Build Real • Verify Skills • Launch Forward