Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zleao/f540ec72756f1d3a6d47143a2a07791f to your computer and use it in GitHub Desktop.
Save zleao/f540ec72756f1d3a6d47143a2a07791f to your computer and use it in GitHub Desktop.
Database creation with throughput in Azure Cosmos DB v3.2 using DocumentDB nuget package
public async Task EnsureDatabaseIsCreatedAsync()
{
using (var client = GetDocumentClient())
{
//set the throughput for the database
var options = new RequestOptions { OfferThroughput = Configuration.AzureDatabaseInitialThroughput };
//create the database without overriding any existing one
await client.CreateDatabaseIfNotExistsAsync(new Microsoft.Azure.Documents.Database { Id = Configuration.DatabaseName }, options);
}
}
private DocumentClient GetDocumentClient()
{
var mongoUrl = new MongoUrl(Configuration.ConnectionString);
var managementPort = Configuration.AzureDatabaseManagementPort;
return new DocumentClient(new Uri($"https://{mongoUrl.Server.Host}:{managementPort}/"), mongoUrl.Password);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment