prakashrajansakthivel
prakashrajansakthivel

Reputation: 2042

Identify from which location cosmosdb query ran against

I am currently using CosmosClient V3. I am trying to figure out which region I am querying against when I have multi region setup. Previously, in V2 (DocumentClient) we were able to do it using connectionPolicy.PreferredLocations where we will be setting the preferred location and using client.ReadEndpoint we will able to verify the current read endpoint chosen based on availability. But in V3 I am able to set the preferred location using ApplicationRegion/LimitToEndpoint, but there is no option to validate the which region the SDK choose for the query like client.ReadEndpoint. Is there any equivalent options available in SDK V3(CosmosClient).

Upvotes: 0

Views: 667

Answers (1)

Matias Quaranta
Matias Quaranta

Reputation: 15603

You don't need to use LimitToEndpoint. As per the comment on that property:

When the value of this property is false, the SDK will automatically discover write and read regions, and use them when the configured application region is not available. When set to true, availability is limited to the endpoint specified on the CosmosClient constructor. Defining the ApplicationRegion is not allowed when setting the value to true.

You need to set the ApplicationRegion, which will make the SDK connect to the closest endpoint based on the account's regions. If your account has one of the regions matching the one the application is in, then it will use that one, otherwise, it will pick the closest one.

You can check the Diagnostics in the query FeedResponse to see which was the region used (please update to the latest SDK).

Upvotes: 1

Related Questions