Soru

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

You are developing a .NET application that stores user session data in an Azure Cosmos DB container. The container's partition key path is set to `/userId`. You need to perform point operations using the Azure Cosmos DB .NET SDK v3 to read and update a user's session data. To ensure session-level consistency across multiple independent clients, you must pass the session token obtained from the writer client to the reader client. Assuming `container` is a valid `Container` instance, `sessionData` is a populated `SessionData` object, and `writerSessionToken` is the session token from the writing client, which two of the following C# statements should you use to perform these operations? (Select two.)

  1. ItemResponse<SessionData> response = await container.ReadItemAsync<SessionData>("session-101", new PartitionKey("user-202"), new ItemRequestOptions { SessionToken = writerSessionToken });Cevap
  2. ItemResponse<SessionData> response = await container.UpsertItemAsync<SessionData>(sessionData, new PartitionKey("user-202"));Cevap
  3. C
    ItemResponse<SessionData> response = await container.ReadItemAsync<SessionData>("session-101", new PartitionKey("active"));
  4. D
    ItemResponse<SessionData> response = await container.ReadItemAsync<SessionData>("session-101", new PartitionKey("user-202"), new ItemRequestOptions { ConsistencyLevel = ConsistencyLevel.Session });

Cevap

The correct statements are the point read operation that specifies the item ID, the matching user ID partition key, and the shared session token, and the upsert operation that updates the session data using the matching user ID partition key.
The correct answers are the statements that use the correct SDK methods with the appropriate partition key. The point read statement must use the item ID, the correct partition key based on the /userId path (in this case, the user ID 'user-202'), and pass the session token from the writing client via the ItemRequestOptions to guarantee session consistency. The upsert statement must save the session data object using the correct user ID partition key.

Adım Adım Çözüm

1
Identify the required parameters for Azure Cosmos DB .NET SDK v3 point operations.
Point operations like ReadItemAsync and UpsertItemAsync require the item identifier and the PartitionKey parameter to match the container's partition key path (/userId).
To perform efficient item operations, the SDK must route the request to the correct physical partition using the logical partition key.
2
Apply the session token to achieve read-your-writes consistency across separate clients.
The writer client's session token must be passed to the reader client via ItemRequestOptions.SessionToken.
Setting the consistency level to Session without sharing the token is insufficient for multi-client scenarios.

Anahtar Kavram

Performing point operations with proper partition key routing and session consistency in Cosmos DB SDK v3.
Bu soruyu puanla