Azure Cosmos DB for MongoDB 的数据库或集合的通过 PowerShell 实现的吞吐量 (RU/s) 操作
适用对象: MongoDB
注意
建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az。
本示例需要 Azure PowerShell Az 5.4.0 或更高版本。 运行 Get-Module -ListAvailable Az
,查看已安装哪些版本。
如果需要安装,请参阅安装 Azure PowerShell 模块。
运行 Connect-AzAccount -Environment AzureChinaCloud 以登录到 Azure。
获取吞吐量
# Reference: Az.CosmosDB | https://learn.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Get database or collection throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase" # Keyspace with shared throughput
$collectionName = "myCollection" # Table with dedicated throughput
# --------------------------------------------------
Write-Host "Get database shared throughput"
Get-AzCosmosDBMongoDBDatabaseThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName
Write-Host "Get collection dedicated throughput"
Get-AzCosmosDBMongoDBCollectionThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $collectionName
更新吞吐量
# Reference: Az.CosmosDB | https://learn.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update collection throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$collectionName = "myCollection"
$newRUs = 500
# --------------------------------------------------
$throughput = Get-AzCosmosDBMongoDBCollectionThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $collectionName
$currentRUs = $throughput.Throughput
$minimumRUs = $throughput.MinimumThroughput
Write-Host "Current throughput is $currentRUs. Minimum allowed throughput is $minimumRUs."
if ([int]$newRUs -lt [int]$minimumRUs) {
Write-Host "Requested new throughput of $newRUs is less than minimum allowed throughput of $minimumRUs."
Write-Host "Using minimum allowed throughput of $minimumRUs instead."
$newRUs = $minimumRUs
}
if ([int]$newRUs -eq [int]$currentRUs) {
Write-Host "New throughput is the same as current throughput. No change needed."
}
else {
Write-Host "Updating throughput to $newRUs."
Update-AzCosmosDBMongoDBCollectionThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $collectionName -Throughput $newRUs
}
迁移吞吐量
# Reference: Az.CosmosDB | https://learn.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Migrate a database or collection to autoscale or standard (manual) throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$collectionName = "myCollection"
# --------------------------------------------------
Write-Host "Migrate database with standard throughput to autoscale throughput."
Invoke-AzCosmosDBMongoDBDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName -ThroughputType Autoscale
Write-Host "Migrate database with autoscale throughput to standard throughput."
Invoke-AzCosmosDBMongoDBDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName -ThroughputType Manual
Write-Host "Migrate collection with standard throughput to autoscale throughput."
Invoke-AzCosmosDBMongoDBCollectionThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $collectionName -ThroughputType Autoscale
Write-Host "Migrate collection with autoscale throughput to standard throughput."
Invoke-AzCosmosDBMongoDBCollectionThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $collectionName -ThroughputType Manual
清理部署
运行脚本示例后,可以使用以下命令删除资源组以及与其关联的所有资源。
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
脚本说明
此脚本使用以下命令。 表中的每条命令均链接到特定于命令的文档。
命令 | 注释 |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBMongoDBDatabaseThroughput | 获取指定的 Azure Cosmos DB for MongoDB 数据库的吞吐量值。 |
Get-AzCosmosDBMongoDBCollectionThroughput | 获取指定的 Azure Cosmos DB for MongoDB 集合的吞吐量值。 |
Update-AzCosmosDBMongoDBDatabaseThroughput | 更新 Azure Cosmos DB for MongoDB 数据库的吞吐量值。 |
Update-AzCosmosDBMongoDBCollectionThroughput | 更新 Azure Cosmos DB for MongoDB 集合的吞吐量值。 |
Invoke-AzCosmosDBMongoDBDatabaseThroughputMigration | 迁移 Azure Cosmos DB for MongoDB 集合的吞吐量。 |
Invoke-AzCosmosDBMongoDBCollectionThroughputMigration | 迁移 Azure Cosmos DB for MongoDB 集合的吞吐量。 |
Azure 资源组 | |
Remove-AzResourceGroup | 删除资源组,包括所有嵌套的资源。 |
后续步骤
有关 Azure PowerShell 的详细信息,请参阅 Azure PowerShell 文档。