CollectionSizeQuota and DocumentQuota in Cosmos DB SDK v3

Viewed 44

I am currently working on migrate Azure Cosmos DB sdk v2 to v3. In my previous codes, there are some usage like:

using Microsoft.Azure.Document.Client

public string functionA(ResourceResponse<T> response)
{
  return string.Format(
      "collection size quota: {0}, document quota: {1}",
      response.CollectionSizeQuota,
      response.DocumentQuota);
}

I am trying to find the equivalent properties/methods of CollectionSizeQuota and DocumentQuota in ItemResponse from Microsoft.Azure.Cosmos, but couldn't. Does anyone know how could I get these info? Thanks in advance.

1 Answers

These are available as part of headers with container operation. You will need to enable PopulateQuotaInfo in the request and use the header values like below,

ContainerRequestOptions containerRequest = new ContainerRequestOptions();
containerRequest.PopulateQuotaInfo = true;
ContainerResponse containerResponse = await container.ReadContainerAsync(containerRequest);
Headers headers = containerResponse.Headers;
Related