Microsoft Certified: Azure Developer Associate Azure Cosmos DB Development 2 — Questions and Answers
Question 1: Which method in the Azure Cosmos DB .NET SDK v3 is used to create or replace an item if it already exists?
- CreateItemAsync
- InsertItemAsync
- UpsertItemAsync (Correct answer)
- ReplaceItemAsync
Correct answer: UpsertItemAsync
UpsertItemAsync creates the item if it does not exist or replaces it if it does, making it idempotent for create-or-update scenarios.
Question 2: In Azure Cosmos DB SQL API queries, which clause is required when querying across all partitions?
- CROSS PARTITION JOIN
- PARTITION BY
- ENABLE CROSS PARTITION QUERY (Correct answer)
- ALLOW CROSS PARTITION
Correct answer: ENABLE CROSS PARTITION QUERY
When executing a cross-partition query via the SDK, you must set EnableCrossPartitionQuery = true in QueryRequestOptions; without a partition key filter, queries fan out to all partitions.
Question 3: What is the Azure Cosmos DB change feed?
- A log of all schema changes to a container
- A sorted list of changes to items in a container that can be read by consumers (Correct answer)
- A real-time feed of pricing changes for RU/s
- A notification service for Cosmos DB quota limits
Correct answer: A sorted list of changes to items in a container that can be read by consumers
The change feed is a persistent log of changes (inserts and updates) to items in a Cosmos DB container, readable in order by partition key within each partition.
Question 4: Which of the following is a correct way to read a single item by its ID in Azure Cosmos DB .NET SDK v3?
- container.QueryItemsAsync<T>(id)
- container.ReadItemAsync<T>(id, new PartitionKey(pk)) (Correct answer)
- container.GetItemAsync<T>(id)
- container.FetchItemAsync<T>(id, pk)
Correct answer: container.ReadItemAsync<T>(id, new PartitionKey(pk))
ReadItemAsync requires both the item ID and partition key value and is the most efficient single-item read (a point read costing 1 RU).
Question 5: Which indexing policy mode in Azure Cosmos DB indexes all paths by default?
- Lazy
- None
- Custom
- Consistent (Correct answer)
Correct answer: Consistent
Consistent indexing (the default) synchronously indexes all item paths on every write, enabling immediate query consistency.
Question 6: What is the purpose of a stored procedure in Azure Cosmos DB?
- To schedule recurring maintenance tasks on a container
- To execute a batch of operations as an ACID transaction within a single partition (Correct answer)
- To replicate data between regions automatically
- To manage container throughput dynamically
Correct answer: To execute a batch of operations as an ACID transaction within a single partition
Stored procedures in Cosmos DB are JavaScript functions executed server-side and provide ACID transaction guarantees, but only within a single logical partition.
Question 7: In Azure Cosmos DB, what NuGet package is used for the modern .NET SDK v3?
- Microsoft.Azure.DocumentDB
- Microsoft.Azure.Cosmos (Correct answer)
- Azure.Data.Cosmos
- Microsoft.Azure.CosmosDB.SDK
Correct answer: Microsoft.Azure.Cosmos
The Microsoft.Azure.Cosmos NuGet package is the official v3 SDK for .NET, replacing the older Microsoft.Azure.DocumentDB package.
Which method in the Azure Cosmos DB .NET SDK v3 is used to create or replace an item if it already exists?