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.)
- ItemResponse<SessionData> response = await container.ReadItemAsync<SessionData>("session-101", new PartitionKey("user-202"), new ItemRequestOptions { SessionToken = writerSessionToken });Answer
- ItemResponse<SessionData> response = await container.UpsertItemAsync<SessionData>(sessionData, new PartitionKey("user-202"));Answer
- CItemResponse<SessionData> response = await container.ReadItemAsync<SessionData>("session-101", new PartitionKey("active"));
- DItemResponse<SessionData> response = await container.ReadItemAsync<SessionData>("session-101", new PartitionKey("user-202"), new ItemRequestOptions { ConsistencyLevel = ConsistencyLevel.Session });
Answer
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.
Step-by-Step Solution
Key Concept
Performing point operations with proper partition key routing and session consistency in Cosmos DB SDK v3.