I am using the Microsoft.Azure.Cosmos SDK (for SQL API) to read items from Azure Cosmos DB. Under this SDK, while reading the items (using container.ReadItemAsync) we can override the default consistencyLevel (that is set at the database level in the Azure portal) at below two places:
- While creating a CosmosClient we can specify the ConsistencyLevel under the CosmosClientOptions. The documentation for this property is: "Summary: This can be used to weaken the database account consistency level for read operations. If this is not set the database account consistency level will be used for all requests."
- While triggering the container.ReadItemAsync request, we can specify the ConsistencyLevel under the ItemRequestOptions. The documentation for the property is: "Summary: Gets or sets the consistency level required for the request in the Azure Cosmos DB service. While this is set at a database account level, Azure Cosmos DB allows a developer to override the default consistency level for each individual request."
Both the properties indicate that they override the default consistency that is specified at the database account level (from the Azure portal).
Now, if I have the default consistency as "Strong" at database account level (in the Azure portal) and I override the consistency level to "Session" while creating a CosmosClient (using CosmosClientOptions) as below:
var clientOption = new CosmosClientOptions
{
ConsistencyLevel = ConsistencyLevel.Session
};
var cosmosClient = new CosmosClient(connectionString, clientOption);
Now, when I try to read an item using container.ReadItemAsync (with the container fetched using the CosmosClient I just created) and do not specify any ConsistencyLevel under ItemRequestOptions as below:
var itemRequestOptions = new ItemRequestOptions();
container.ReadItemAsync<string>(id, partitionKey, itemRequestOptions)
Now what is the consistency level at which the read operation is performed (Strong or Session)?