Soru

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

You are developing a C# application using the Azure Cosmos DB .NET SDK v3 to manage configuration settings for a multi-tenant SaaS application. The target container uses '/tenantId' as its partition key path. You need to retrieve a single configuration item with an id of 'config-100' for a tenant whose tenantId is 'tenant-99' using the most efficient operation (lowest latency and RU cost). Which code segment should you use?

  1. ItemResponse<TenantConfig> response = await container.ReadItemAsync<TenantConfig>("config-100", new PartitionKey("tenant-99"));Cevap
  2. B
    ItemResponse<TenantConfig> response = await container.ReadItemAsync<TenantConfig>("config-100");
  3. C
    FeedIterator<TenantConfig> response = container.GetItemQueryIterator<TenantConfig>("SELECT * FROM c WHERE c.id = 'config-100'");
  4. D
    ItemResponse<TenantConfig> response = await container.ReadItemAsync<TenantConfig>("config-100", new PartitionKey("config-100"));

Cevap

ItemResponse<TenantConfig> response = await container.ReadItemAsync<TenantConfig>("config-100", new PartitionKey("tenant-99"));
The correct option uses the ReadItemAsync method, passing the item ID ('config-100') and the partition key ('tenant-99') as arguments. This constitutes a point read, which is the most efficient operation in Cosmos DB, providing the lowest latency and costing only 1 Request Unit (RU) for items under 1 KB.

Adım Adım Çözüm

1
Determine the most efficient SDK operation for single-item retrieval.
A point read (ReadItemAsync) is selected over a query (GetItemQueryIterator) because it bypasses the query engine and executes in under 1 RU for items up to 1 KB.
Point reads are the fastest and most cost-effective way to read a single item in Azure Cosmos DB.
2
Supply the mandatory parameters to the ReadItemAsync method.
Pass the item ID ('config-100') as the first parameter, and the PartitionKey object instantiated with the logical partition key value ('tenant-99') as the second parameter.
The .NET SDK v3 requires both the item ID and the logical partition key value to perform a point read.

Anahtar Kavram

Performing point reads using the Azure Cosmos DB .NET SDK v3.
Tahmini Süre:45s
Bu soruyu puanla