Operace propustnosti (RU/s) s využitím PowerShellu pro databázi nebo kolekci pro Azure Cosmos DB pro MongoDB

PLATÍ PRO: MongoDB

Poznámka

K interakci s Azure doporučujeme použít modul Azure Az PowerShell. Začněte tím, že si projdete téma Instalace Azure PowerShellu. Informace o tom, jak migrovat na modul Az PowerShell, najdete v tématu Migrace Azure PowerShellu z AzureRM na Az.

Tato ukázka vyžaduje Azure PowerShell Az 5.4.0 nebo novější. Spuštěním příkazu Get-Module -ListAvailable Az zjistěte, které verze jsou nainstalované. Pokud potřebujete instalaci, přečtěte si téma Instalace modulu Azure PowerShell.

Spusťte Connect-AzAccount a přihlaste se k Azure.

Zjištění propustnosti

# 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

Aktualizace propustnosti

# 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
}

Propustnost migrace

# 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

Vyčištění nasazení

Po spuštění ukázkového skriptu můžete pomocí následujícího příkazu odebrat skupinu prostředků a všechny k ní přidružené prostředky.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Vysvětlení skriptu

Tento skript používá následující příkazy. Každý příkaz v tabulce odkazuje na příslušnou část dokumentace.

Příkaz Poznámky
Azure Cosmos DB
Get-AzCosmosDBMongoDBDatabaseThroughput Získá hodnotu propustnosti zadané databáze Azure Cosmos DB pro MongoDB.
Get-AzCosmosDBMongoDBCollectionThroughput Získá hodnotu propustnosti zadané kolekce Azure Cosmos DB pro MongoDB.
Update-AzCosmosDBMongoDBDatabaseThroughput Aktualizace hodnotu propustnosti databáze Azure Cosmos DB pro MongoDB.
Update-AzCosmosDBMongoDBCollectionThroughput Aktualizace hodnotu propustnosti kolekce Azure Cosmos DB pro MongoDB.
Invoke-AzCosmosDBMongoDBDatabaseThroughputMigration Migrace propustnosti kolekce Azure Cosmos DB pro MongoDB
Invoke-AzCosmosDBMongoDBCollectionThroughputMigration Migrace propustnosti kolekce Azure Cosmos DB pro MongoDB
Skupiny prostředků Azure
Remove-AzResourceGroup Odstraní skupinu prostředků včetně všech vnořených prostředků.

Další kroky

Další informace o Azure PowerShellu najdete v dokumentaci k Azure PowerShellu.