Different ways to deploy CosmosDB artefacts

I will show you two ways to deploy azure CosmosDb artefacts.

Cosmos SDKs for SQL API

Documentation: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-dotnet-standard
GitHub: https://github.com/Azure/azure-cosmos-dotnet-v3
Nuget: https://www.nuget.org/packages/Microsoft.Azure.Cosmos/
Samples: https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage
The SDK name maybe confuses people, but you can use this SDK for all CosmosDB APIs (Cassandra API has issues with throughput). I think they will change this soon, because the prerelease Nuget Package already is named Microsoft Azure Cosmos.
It can do 2 things:

  1. Create CosmosDb artefacts (Db/collection/documents) - not a CosmosDb account
  2. Query CosmosDb documents

Samples

Source: https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-provision-container-throughput

//create the database with throughput
string databaseName = "MyDatabaseName";
await this.cosmosClient.CreateDatabaseIfNotExistsAsync(
        id: databaseName,
        throughput: 400);
// Create a container with a partition key and provision throughput of 1000 RU/s
string containerName = "myContainerName";
string partitionKeyPath = "/myPartitionKey";

await this.cosmosClient.GetDatabase("myDatabase").CreateContainerAsync(
    id: containerName,
    partitionKeyPath: partitionKeyPath,
    throughput: 1000);

Azure libraries for .Net

GitHub: https://github.com/Azure/azure-libraries-for-net
Samples: https://github.com/Azure/azure-libraries-for-net/tree/master/Samples
This is the general library for deploying Azure resources and can't query any documents from CosmosDb. It's can only create azure resources.
Following CosmosDB artefacts can be created (+ nearly all azure artefacts):

  • CosmosDB account
  • CosmosDB database
  • CosmosDB collection

Samples

Here you can find some samples for creating these artefacts with configured throughput: https://developers.de/2020/03/12/mongo-cosmosdb-deploy-with-throughput/


comments powered by Disqus