1

I want to do a Ping Like Operation on a Cosmos/Mongo/DocumentDB in Azure.

The Collection Has Zero Documents in it.

I am Using the Microsoft.Azure.Documents.Client (Microsoft.Azure.Documents.Client.dll)

I want to do something that would exercise a full round trip and auth cycle to the Cosmos DB to prove the general integrity of the config before any documents are in the collection.

I was looking for an operation on DocumentClient that would prove or disprove all the configuration is correct at runtime, like a Ping.

1 Answer 1

2

You could call _client.OpenAsync(cancellationToken), which will validate your configuration and throw if there are any exceptions connecting to the database.

In fact, it is recommended that you call this on service/app startup to avoid latency on your first request.

Reference:

2
  • It's worth noting that this method doesn't exist in the .NET Standard version of the library. Commented Jul 25, 2018 at 8:20
  • This Lead to me stumbling onto ReadDocumentCollectionAsync also. With that I can log the property AltLink which lets me log and confirm the actual connected collection that is being used at run time.
    – Sql Surfer
    Commented Jul 26, 2018 at 12:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.