Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Implement create, replace, update, patch and delete operations

A worked example

Yes or no

Contoso stores order documents of about 400 KB each in an Azure Cosmos DB for NoSQL container named orders, partitioned on /customerId. The account has a single write region.

Today, the shipping handler reads each order, changes the status property, and calls replace. The team plans to change it to the patch API. The team also asks about two other updates:

  • A data-correction job must overwrite the scalar values of 12 existing, mutable top-level properties on a single order, retaining all 12 properties.
  • Support staff sometimes need to reassign an order to a different customer.

For each of the following statements, select Yes if the statement is true. Otherwise, select No.

StatementYesNo
The data-correction job can apply all 12 property changes to the order in a single patch request.

A patch request permits at most 10 operations. Overwriting each of these 12 top-level scalar values requires a separate operation, so the job must use several patches or replace the whole document.

Correct
Moving the shipping handler from read-and-replace to a single patch saves the RU charge of the read, while the patch itself is charged about the same as replacing the order.

On a patch, Cosmos DB processes the entire item on the server, just as it does for a replace, so the patch's RU charge is roughly equal to replacing the same document. The saving is the separate read request and its RUs, plus far less network traffic for a 400-KB order.

Correct
Support staff can reassign an order to a different customer with a single patch request that sets /customerId to the new customer's ID.

/customerId is the container's partition key path, and the partition key property is not patchable, since a new value would place the item in another logical partition. Patching a non-key property such as /status is allowed.

Correct
Why

Patch permits up to 10 operations in one request, so these 12 scalar replacements require several requests or a full replace. The partition key property cannot be patched. The patch write generally costs about as many RUs as a replace, while avoiding the preceding read saves its RU charge and reduces network traffic for these large orders.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free