Created
July 11, 2020 15:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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