Operacje przepływności (RU/s) za pomocą programu PowerShell dla bazy danych lub kolekcji dla usługi Azure Cosmos DB dla bazy danych MongoDB

DOTYCZY: Mongodb

Uwaga

Zalecamy korzystanie z modułu Azure Az programu PowerShell do interakcji z platformą Azure. Zobacz Instalowanie programu Azure PowerShell, aby rozpocząć. Aby dowiedzieć się, jak przeprowadzić migrację do modułu Az PowerShell, zobacz Migracja programu Azure PowerShell z modułu AzureRM do modułu Az.

Ten przykład wymaga modułu Azure PowerShell Az 5.4.0 lub nowszego. Uruchom polecenie Get-Module -ListAvailable Az , aby zobaczyć, które wersje są zainstalowane. Jeśli musisz zainstalować, zobacz Instalowanie modułu Azure PowerShell.

Uruchom polecenie Connect-AzAccount , aby zalogować się do platformy Azure.

Uzyskiwanie informacji o przepływności

# 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

Aktualizowanie przepływności

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

Migrowanie przepływności

# 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

Czyszczenie wdrożenia

Po wykonaniu przykładowego skryptu możesz uruchomić następujące polecenie, aby usunąć grupę zasobów i wszystkie skojarzone z nią zasoby.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Objaśnienia dla skryptu

W tym skrypcie użyto następujących poleceń. Każde polecenie w tabeli stanowi link do dokumentacji polecenia.

Polecenie Uwagi
Azure Cosmos DB
Get-AzCosmosDBMongoDBDatabaseThroughput Pobiera wartość przepływności określonej bazy danych Azure Cosmos DB dla bazy danych MongoDB.
Get-AzCosmosDBMongoDBCollectionThroughput Pobiera wartość przepływności określonej kolekcji usługi Azure Cosmos DB dla bazy danych MongoDB.
Update-AzCosmosDBMongoDBDatabaseThroughput Aktualizacje wartość przepływności usługi Azure Cosmos DB dla bazy danych MongoDB.
Update-AzCosmosDBMongoDBCollectionThroughput Aktualizacje wartość przepływności kolekcji usługi Azure Cosmos DB dla bazy danych MongoDB.
Invoke-AzCosmosDBMongoDBDatabaseThroughputMigration Migrowanie przepływności kolekcji usługi Azure Cosmos DB dla bazy danych MongoDB.
Invoke-AzCosmosDBMongoDBCollectionThroughputMigration Migrowanie przepływności kolekcji usługi Azure Cosmos DB dla bazy danych MongoDB.
Grupy zasobów platformy Azure
Remove-AzResourceGroup Usuwa grupę zasobów wraz ze wszystkimi zagnieżdżonymi zasobami.

Następne kroki

Aby uzyskać więcej informacji na temat programu Azure PowerShell, zobacz dokumentację programu Azure PowerShell.