你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure Cosmos DB for MongoDB 资源上预配数据库、容器或自动缩放吞吐量

适用于: MongoDB

本文介绍如何在 Azure Cosmos DB for MongoDB 中预配吞吐量。 你可在一个容器或数据库上预配标准(手动)或自动缩放吞吐量,并在数据库中的容器之间共享。 你可使用 Azure 门户、Azure CLI 或 Azure Cosmos DB SDK 来预配吞吐量。

如果使用的是其他 API,请参阅 API for NoSQLAPI for CassandraAPI for Gremlin 这几篇文章来预配吞吐量。

Azure 门户

  1. 登录 Azure 门户

  2. 新建 Azure Cosmos DB 帐户,或选择现有的 Azure Cosmos DB 帐户。

  3. 打开“数据资源管理器”窗格,然后选择“新建集合” 。 接下来,请提供以下详细信息:

    • 表明要创建新数据库还是使用现有数据库。 如果要在数据库级别预配吞吐量,请选择“预配数据库吞吐量”选项。
    • 输入集合 ID。
    • 输入分区键值(例如 ItemID)。
    • 输入要预配的吞吐量(例如,1000 RU)
    • 选择“确定”。

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

注意

如果要在配置了 Azure Cosmos DB for MongoDB 的 Azure Commos DB 帐户中的容器上预配吞吐量,请使用 myShardKey 作为分区键路径。

.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
// https://learn.microsoft.com/azure/cosmos-db/mongodb-custom-commands#update-collection

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

Azure 资源管理器

Azure 资源管理器模板可用于在数据库或容器级资源上为所有 Azure Cosmos DB API 预配自动缩放吞吐量。 有关示例,请参阅 Azure Cosmos DB 的 Azure 资源管理器模板

Azure CLI

Azure CLI 可用于在数据库或容器级资源上为所有 Azure Cosmos DB API 预配自动缩放吞吐量。 有关示例,请参阅用于 Azure Cosmos DB 的 Azure CLI 示例

Azure PowerShell

Azure PowerShell 可用于在数据库或容器级资源上为所有 Azure Cosmos DB API 预配自动缩放吞吐量。 有关示例,请参阅适用于 Azure Cosmos DB 的 Azure PowerShell 示例

后续步骤

请参阅以下文章,了解如何在 Azure Cosmos DB 中预配吞吐量: