Soru

Zorluk: KolayPerform Container and Item Operations in Azure Cosmos DB using SDK

An IoT application ingests telemetry data and writes it to an Azure Cosmos DB container configured with a partition key of /DeviceId. Which two of the following statements about performing item operations using the Cosmos DB .NET SDK v3 are correct? (Select TWO).

  1. To create a new item, you should call CreateItemAsync<T>(item, new PartitionKey(item.DeviceId)) on the Container instance, passing both the item details and the partition key.Cevap
  2. To retrieve a single item efficiently (a point read), you should call ReadItemAsync<T>(id, new PartitionKey(deviceId)) on the Container instance to avoid a cross-partition query.Cevap
  3. C
    To achieve read-your-writes guarantees (Session consistency) across multiple independent client sessions, you only need to set the consistency level to Session on the CosmosClient without sharing the Session Token.
  4. D
    To optimize ingestion rates, you should select a low-cardinality property (like 'Status') as the partition key and omit the PartitionKey parameter in CreateItemAsync.

Cevap

The correct statements are that creating a new item requires calling CreateItemAsync with the item and a PartitionKey, and retrieving a single item efficiently (point read) requires calling ReadItemAsync with the id and PartitionKey.
The .NET SDK v3 Container class provides methods like CreateItemAsync and ReadItemAsync to perform item-level operations. These operations require the item's partition key to be explicitly passed as a parameter (e.g., using new PartitionKey(value)) to ensure they are directed to the correct physical partition, avoiding performance issues or cross-partition queries.

Adım Adım Çözüm

1
Identify the required parameters for creating items in Cosmos DB .NET SDK v3.
CreateItemAsync requires the document object and the partition key (e.g., new PartitionKey(item.DeviceId)).
This ensures the SDK writes the document to the correct logical and physical partition.
2
Identify the required parameters for retrieving a single item (point read).
ReadItemAsync requires the unique ID and the partition key (e.g., new PartitionKey(deviceId)).
Point reads are the most efficient read operation in Cosmos DB because they bypass the query engine and target the specific partition directly.

Anahtar Kavram

Performing item operations using the Cosmos DB .NET SDK v3
Tahmini Süre:1m 30s
Bu soruyu puanla