You are developing a C# console application that retrieves a specific product configuration document from an Azure Cosmos DB container by using the .NET SDK v3. You need to write the code that performs a point read of the item. Which sequence of actions should you perform to complete this operation? To answer, arrange the actions in the correct order.
- 1Instantiate a CosmosClient object using the Azure Cosmos DB account endpoint URI and authentication credentials.
- 2Call GetDatabase on the CosmosClient object to obtain a reference to the target database.
- 3Call GetContainer on the Database object to obtain a reference to the target container.
- 4Instantiate a PartitionKey structure using the partition key value of the target document.
- 5Call ReadItemAsync on the Container object, passing the item's unique identifier and the PartitionKey object.
Answer
To perform a point read, you must first instantiate a CosmosClient. Next, call GetDatabase on the CosmosClient to retrieve the Database reference. Then, call GetContainer on the Database to retrieve the Container reference. After that, initialize a PartitionKey structure with the partition key value. Finally, call ReadItemAsync on the Container, passing the unique identifier and the PartitionKey.
The correct sequence starts with instantiating the CosmosClient, which establishes the connection pool. You then call GetDatabase on the client and GetContainer on the database to navigate the SDK hierarchy. Before executing the read, you instantiate the PartitionKey with the target value. Finally, you execute the point read by calling ReadItemAsync on the container with the item ID and PartitionKey.
Step-by-Step Solution
Key Concept
Executing container and item operations using the Azure Cosmos DB .NET SDK v3 requires initializing the CosmosClient, obtaining Database and Container references, and providing a PartitionKey to the item operation method.