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?
- ItemResponse<TenantConfig> response = await container.ReadItemAsync<TenantConfig>("config-100", new PartitionKey("tenant-99"));Answer
- BItemResponse<TenantConfig> response = await container.ReadItemAsync<TenantConfig>("config-100");
- CFeedIterator<TenantConfig> response = container.GetItemQueryIterator<TenantConfig>("SELECT * FROM c WHERE c.id = 'config-100'");
- DItemResponse<TenantConfig> response = await container.ReadItemAsync<TenantConfig>("config-100", new PartitionKey("config-100"));
Answer
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.
Step-by-Step Solution
Key Concept
Performing point reads using the Azure Cosmos DB .NET SDK v3.
Estimated Time:45s