Provision database, container or autoscale throughput on Azure Cosmos DB for MongoDB resources

APPLIES TO: MongoDB

Important

Are you looking to migrate an existing MongoDB application or use MongoDB Query Language (MQL) features? Consider Azure DocumentDB.

Are you looking for a database solution for high-scale scenarios with a 99.999% availability service level agreement (SLA), instant autoscale, and automatic failover across multiple regions? Consider Azure Cosmos DB for NoSQL.

This article explains how to provision throughput in Azure Cosmos DB for MongoDB. You can provision standard(manual) or autoscale throughput on a collection, or a database and share it among the collections within the database. You can provision throughput using Azure portal, Azure CLI, or Azure Cosmos DB SDKs.

Note

Shared database throughput is not recommended for most workloads. While it can simplify provisioning in some scenarios, sharing throughput across multiple collections can lead to unpredictable and undesirable performance and scale behaviors. Because collections in the same database share partitions, scaling database throughput to support a large or growing collection may trigger repartitioning of smaller, co‑located collections, spreading them overly thin across too many partitions. We recommend configuring throughput at the collection level. Customers with advanced scenarios who understand these tradeoffs can still create and manage shared database throughput programmatically using the Azure Cosmos DB SDKs.

If you are using a different API, see API for NoSQL, API for Cassandra, API for Gremlin articles to provision the throughput.

Azure portal

  1. Sign in to the Azure portal.

  2. Create a new Azure Cosmos DB account, or select an existing Azure Cosmos DB account.

  3. Open the Data Explorer pane, and select New Collection. Next, provide the following details:

    • Indicate whether you are creating a new database or using an existing one.
    • Enter a collection ID.
    • Enter a partition key value (for example, ItemID).
    • Enter a throughput that you want to provision (for example, 1000 RUs).
    • Select OK.

    Screenshot of Data Explorer, when creating a new collection with database level throughput

Note

For most workloads, we recommend provisioning throughput at the collection level rather than the database level. If you have an advanced scenario that requires shared database throughput, you can create it programmatically using the Azure Cosmos DB SDKs.

Note

If you are provisioning throughput on a container in an Azure Cosmos DB account configured with the Azure Cosmos DB for MongoDB, use myShardKey for the partition key path.

.NET SDK

// refer to MongoDB .NET Driver
// https://docs.mongodb.com/drivers/csharp

// Create a new Client
String mongoConnectionString = "mongodb://DB AccountName:Password@DB AccountName.documents.azure.com:10255/?ssl=true&replicaSet=globaldb";
mongoUrl = new MongoUrl(mongoConnectionString);
mongoClientSettings = MongoClientSettings.FromUrl(mongoUrl);
mongoClient = new MongoClient(mongoClientSettings);

// Change the database name
mongoDatabase = mongoClient.GetDatabase("testdb");

// Change the collection name, throughput value then update via MongoDB extension commands
// /azure/cosmos-db/mongodb-custom-commands#update-collection

var result = mongoDatabase.RunCommand<BsonDocument>(@"{customAction: ""UpdateCollection"", collection: ""testcollection"", offerThroughput: 400}");

Azure Resource Manager

Azure Resource Manager templates can be used to provision autoscale throughput on database or container-level resources for all Azure Cosmos DB APIs. See Azure Resource Manager templates for Azure Cosmos DB for samples.

Azure CLI

Azure CLI can be used to provision autoscale throughput on a database or container-level resources for all Azure Cosmos DB APIs. For samples see Azure CLI Samples for Azure Cosmos DB.

Azure PowerShell

Azure PowerShell can be used to provision autoscale throughput on a database or container-level resources for all Azure Cosmos DB APIs. For samples see Azure PowerShell samples for Azure Cosmos DB.

Next steps

See the following articles to learn about throughput provisioning in Azure Cosmos DB: