I checked the MSDN on DocumentDB for .Net (here) and found 3 valid constructors. However none of them makes use of connection strings, which sounds strange for me.
I
You can actually do this in a roundabout way.
internal class CosmosDBConnectionString
{
public CosmosDBConnectionString(string connectionString)
{
// Use this generic builder to parse the connection string
DbConnectionStringBuilder builder = new DbConnectionStringBuilder
{
ConnectionString = connectionString
};
if (builder.TryGetValue("AccountKey", out object key))
{
AuthKey = key.ToString();
}
if (builder.TryGetValue("AccountEndpoint", out object uri))
{
ServiceEndpoint = new Uri(uri.ToString());
}
}
public Uri ServiceEndpoint { get; set; }
public string AuthKey { get; set; }
}
Then
var cosmosDBConnectionString = new CosmosDBConnectionString(connectionString)
var client = new DocumentClient(
cosmosDBConnectionString.ServiceEndpoint,
cosmosDBConnectionString.AuthKey)
This is taken from the Azure WebJobs Extensions SDK, which is how Azure Functions V2 is able to work with just a connection string. Saves having to try and parse the string yourself.