在 Azure Cosmos DB API for MongoDB 资源上预配数据库、容器或自动缩放吞吐量Provision database, container or autoscale throughput on Azure Cosmos DB API for MongoDB resources

适用于: Azure Cosmos DB API for MongoDB

本文介绍如何在 Azure Cosmos DB API for MongoDB 中预配吞吐量。This article explains how to provision throughput in Azure Cosmos DB API for MongoDB. 你可在一个容器或数据库上预配标准(手动)或自动缩放吞吐量,并在数据库中的容器之间共享。You can provision standard(manual) or autoscale throughput on a container, or a database and share it among the containers within the database. 你可使用 Azure 门户、Azure CLI 或 Azure Cosmos DB SDK 来预配吞吐量。You can provision throughput using Azure portal, Azure CLI, or Azure Cosmos DB SDKs.

如果你使用不同的 API,请参阅 SQL APICassandra APIGremlin API 文章来预配吞吐量。If you are using a different API, see SQL API, Cassandra API, Gremlin API articles to provision the throughput.

Azure 门户Azure portal

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 创建新的 Azure Cosmos 帐户,或选择现有的 Azure Cosmos 帐户。Create a new Azure Cosmos account, or select an existing Azure Cosmos 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. 如果要在数据库级别预配吞吐量,请选择“预配数据库吞吐量”选项。Select the Provision database throughput option if you want to provision throughput at the database level.
    • 输入集合 ID。Enter a collection ID.
    • 输入分区键值(例如 /ItemID)。Enter a partition key value (for example, /ItemID).
    • 输入要预配的吞吐量(例如,1000 RU)Enter a throughput that you want to provision (for example, 1000 RUs).
    • 选择“确定”。Select OK.

    创建具有数据库级吞吐量的新集合时的数据资源管理器的屏幕截图

备注

若要在 Azure Cosmos DB 帐户(使用用于 MongoDB 的 Azure Cosmos DB API)为容器预配吞吐量,请使用 /myShardKey 作为分区键路径。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.

.NET SDK.NET SDK

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

// Create a new Client
String mongoConnectionString = "mongodb://DBAccountName:Password@DBAccountName.documents.azure.cn: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
// https://docs.azure.cn/cosmos-db/mongodb-custom-commands#update-collection

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

Azure 资源管理器Azure Resource Manager

Azure 资源管理器模板可用于在数据库或容器级资源上为所有 Azure Cosmos DB API 预配自动缩放吞吐量。Azure Resource Manager templates can be used to provision autoscale throughput on database or container-level resources for all Azure Cosmos DB APIs. 有关示例,请参阅 Azure Cosmos DB 的 Azure 资源管理器模板See Azure Resource Manager templates for Azure Cosmos DB for samples.

Azure CLIAzure CLI

Azure CLI 可用于在数据库或容器级资源上为所有 Azure Cosmos DB API 预配自动缩放吞吐量。Azure CLI can be used to provision autoscale throughput on a database or container-level resources for all Azure Cosmos DB APIs. 有关示例,请参阅用于 Azure Cosmos DB 的 Azure CLI 示例For samples see Azure CLI Samples for Azure Cosmos DB.

Azure PowerShellAzure PowerShell

Azure PowerShell 可用于在数据库或容器级资源上为所有 Azure Cosmos DB API 预配自动缩放吞吐量。Azure PowerShell can be used to provision autoscale throughput on a database or container-level resources for all Azure Cosmos DB APIs. 有关示例,请参阅适用于 Azure Cosmos DB 的 Azure PowerShell 示例For samples see Azure PowerShell samples for Azure Cosmos DB.

后续步骤Next steps

请参阅以下文章,了解如何在 Azure Cosmos DB 中预配吞吐量:See the following articles to learn about throughput provisioning in Azure Cosmos DB: