Skip to content

Commit e49a679

Browse files
Merge pull request #96218 from SnehaGunda/master
Adding provisioning/updating container throughput with JavaScript example
2 parents f26b48b + 7a1c97e commit e49a679

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

articles/cosmos-db/how-to-provision-container-throughput.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.author: mjbrown
1212

1313
This article explains how to provision throughput on a container (collection, graph, or table) in Azure Cosmos DB. You can provision throughput on a single container, or [provision throughput on a database](how-to-provision-database-throughput.md) and share it among the containers within the database. You can provision throughput on a container using Azure portal, Azure CLI, or Azure Cosmos DB SDKs.
1414

15-
## Provision throughput using Azure portal
15+
## Azure portal
1616

1717
1. Sign in to the [Azure portal](https://portal.azure.com/).
1818

@@ -28,7 +28,7 @@ This article explains how to provision throughput on a container (collection, gr
2828

2929
![Screenshot of Data Explorer, with New Collection highlighted](./media/how-to-provision-container-throughput/provision-container-throughput-portal-all-api.png)
3030

31-
## Provision throughput using Azure CLI or PowerShell
31+
## Azure CLI or PowerShell
3232

3333
To create a container with dedicated throughput see,
3434

@@ -38,7 +38,7 @@ To create a container with dedicated throughput see,
3838
> [!Note]
3939
> If you are provisioning throughput on a container in an Azure Cosmos account configured with the Azure Cosmos DB API for MongoDB, use `/myShardKey` for the partition key path. If you are provisioning throughput on a container in an Azure Cosmos account configured with Cassandra API, use `/myPrimaryKey` for the partition key path.
4040
41-
## Provision throughput by using .NET SDK
41+
## .NET SDK
4242

4343
> [!Note]
4444
> Use the Cosmos SDKs for SQL API to provision throughput for all Cosmos DB APIs, except Cassandra API.
@@ -61,7 +61,37 @@ await client.CreateDocumentCollectionAsync(
6161
### .Net V3 SDK
6262
[!code-csharp[](~/samples-cosmosdb-dotnet-v3/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SampleCodeForDocs/ContainerDocsSampleCode.cs?name=ContainerCreateWithThroughput)]
6363

64+
## JavaScript SDK
65+
66+
```javascript
67+
// Create a new Client
68+
const client = new CosmosClient({ endpoint, key });
69+
70+
// Create a database
71+
const { database } = await client.databases.createIfNotExists({ id: "databaseId" });
72+
73+
// Create a container with the specified throughput
74+
const { resource } = await database.containers.createIfNotExists({
75+
id: "contaierId ",
76+
throughput: 1000
77+
});
78+
79+
// To update an existing container or databases throughput, you need to user the offers API
80+
// Get all the offers
81+
const { resources: offers } = await client.offers.readAll().fetchAll();
82+
83+
// Find the offer associated with your container or the database
84+
const offer = offers.find((_offer) => _offer.offerResourceId === resource._rid);
85+
86+
// Change the throughput value
87+
offer.content.offerThroughput = 2000;
88+
89+
// Replace the offer.
90+
await client.offer(offer.id).replace(offer);
91+
```
92+
6493
### <a id="dotnet-cassandra"></a>Cassandra API
94+
6595
Similar commands can be issued through any CQL-compliant driver.
6696

6797
```csharp

0 commit comments

Comments
 (0)