Operações de taxa de transferência (RU/s) com o PowerShell para um banco de dados ou uma coleção para o Azure Cosmos DB for MongoDB
APLICA-SE AO: MongoDB
Observação
Recomendamos que você use o módulo Az PowerShell do Azure para interagir com o Azure. Para começar, consulte Instalar o Azure PowerShell. Para saber como migrar para o módulo Az PowerShell, confira Migrar o Azure PowerShell do AzureRM para o Az.
Este exemplo exige o Azure PowerShell Az 5.4.0 ou posterior. Execute Get-Module -ListAvailable Az
para ver quais versões estão instaladas.
Se é preciso instalar, consulte Instalar o módulo do Azure PowerShell.
Execute Connect-AzAccount para entrar no Azure.
Obter taxa de transferência
# Reference: Az.CosmosDB | https://docs.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
Atualizar a taxa de transferência
# Reference: Az.CosmosDB | https://docs.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
}
Migrar a taxa de transferência
# Reference: Az.CosmosDB | https://docs.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
Limpar a implantação
Após a execução do script de exemplo, o comando a seguir pode ser usado para remover o grupo de recursos e todos os recursos associados a ele.
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
Explicação sobre o script
Este script usa os comandos a seguir. Cada comando da tabela é vinculado à documentação específica do comando.
Comando | Observações |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBMongoDBDatabaseThroughput | Obtém o valor da taxa de transferência do banco de dados especificado do Azure Cosmos DB for MongoDB. |
Get-AzCosmosDBMongoDBCollectionThroughput | Obtém o valor da taxa de transferência da coleção especificada do Azure Cosmos DB for MongoDB. |
Update-AzCosmosDBMongoDBDatabaseThroughput | Atualiza o valor da taxa de transferência do banco de dados do Azure Cosmos DB for MongoDB. |
Update-AzCosmosDBMongoDBCollectionThroughput | Atualiza o valor da taxa de transferência da coleção do Azure Cosmos DB for MongoDB. |
Invoke-AzCosmosDBMongoDBDatabaseThroughputMigration | Migre a taxa de transferência de uma coleção do Azure Cosmos DB for MongoDB. |
Invoke-AzCosmosDBMongoDBCollectionThroughputMigration | Migre a taxa de transferência de uma coleção do Azure Cosmos DB for MongoDB. |
Grupos de recursos do Azure | |
Remove-AzResourceGroup | Exclui um grupo de recursos, incluindo todos os recursos aninhados. |
Próximas etapas
Para obter mais informações sobre o Azure PowerShell, confira a Documentação do Azure PowerShell.