Microsoft Azure Developer Associate AZ-204 Practice Question
You are building an Azure Function that writes employee documents to an Azure Cosmos DB container by using the .NET SDK v3. Each document is uniquely identified by employeeId, and the container is partitioned on /departmentId. The function must create the document if it is missing or update it in a single request without a prior read. Which Container method should you call to meet this requirement?
UpsertItemAsync(item, new PartitionKey(departmentId))
ReplaceItemAsync(itemId, item, new PartitionKey(departmentId))
CreateItemAsync(item, new PartitionKey(departmentId))
PatchItemAsync(itemId, patchOperations, new PartitionKey(departmentId))
The only SDK operation that both inserts and replaces a document in one request is the upsert operation. When UpsertItemAsync is called, Cosmos DB attempts to create the item; if an item with the same id and partition key already exists, it is replaced atomically. CreateItemAsync fails with a 409 Conflict when the item exists, while ReplaceItemAsync and PatchItemAsync require the item to be present and would throw 404 NotFound if it does not exist. Therefore, UpsertItemAsync satisfies the requirement to avoid a preliminary read while ensuring idempotent create-or-update behavior.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the partition key in Azure Cosmos DB?
Open an interactive chat with Bash
How does the UpsertItemAsync method work in Cosmos DB's .NET SDK v3?
Open an interactive chat with Bash
Why is CreateItemAsync not ideal for create-or-update scenarios in Cosmos DB?
Open an interactive chat with Bash
Microsoft Azure Developer Associate AZ-204
Develop for Azure storage
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .