Queries
From Ilianko
← Back to DP-420 Terminology Reference
Category: Server-Side Programming
Summary: Queries
Overview
using Microsoft.Azure.Cosmos;
using System;
using System.Threading.Tasks;
public async Task RunParameterizedQueryAsync(Container container, string customerId, string status)
{
// 1. Define the SQL query text using parameter placeholders (@customerId, @status)
string sqlText = "SELECT * FROM c WHERE c.customerId = @customerId AND c.status = @status";
// 2. Create the QueryDefinition and bind the dynamic values safely
QueryDefinition queryDefinition = new QueryDefinition(sqlText)
.WithParameter("@customerId", customerId)
.WithParameter("@status", status);
// 3. Execute the query using GetItemQueryIterator
using FeedIterator feedIterator = container.GetItemQueryIterator(queryDefinition);
while (feedIterator.HasMoreResults)
{
FeedResponse response = await feedIterator.ReadNextAsync();
foreach (Order order in response)
{
Console.WriteLine($"Found Order ID: {order.Id}");
}
}
}
More Info & Links
DP-420 Style Practice Questions
Q1. What does a 429 error from Azure Cosmos DB typically indicate?
- A. The request was throttled because provisioned throughput (RU/s) was exceeded
- B. The requested item does not exist
- C. An authentication failure occurred
- D. A conflict occurred during multi-region writes
Q2. Which of these could help reduce the frequency of 429 errors?
- A. Improving partition key distribution to avoid hot partitions, or increasing provisioned RU/s
- B. Disabling the SDK's automatic retry policy
- C. Switching to gateway mode exclusively
- D. Reducing the number of properties indexed
Answer Key
Answers are listed at the very end so you can attempt the questions first.
- Q1 (429 Throttling Error): A. The request was throttled because provisioned throughput (RU/s) was exceeded — A 429 status code means the request rate exceeded the provisioned RU/s, triggering throttling.
- Q2 (429 Throttling Error): A. Improving partition key distribution to avoid hot partitions, or increasing provisioned RU/s — Better partition key distribution and/or higher provisioned throughput both help reduce 429 throttling errors.
DP-420: Designing and Implementing Cloud-Native Applications Using Microsoft Azure Cosmos DB — term detail page