MongoDB için Azure Cosmos DB için veritabanı veya graf için Azure CLI ile aktarım hızı (RU/sn) işlemleri

ŞUNLAR IÇIN GEÇERLIDIR: MongoDB

Bu makaledeki betik, ayrılmış aktarım hızına sahip paylaşılan aktarım hızına ve koleksiyona sahip bir MongoDB veritabanı oluşturur, ardından her ikisi için de aktarım hızını güncelleştirir. Betik daha sonra standarttan otomatik ölçeklendirme aktarım hızına geçirildikten sonra otomatik ölçeklendirme aktarım hızının değerini okur.

Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.

Ön koşullar

  • Azure Cloud Shell'de Bash ortamını kullanın. Daha fazla bilgi için bkz . Azure Cloud Shell'de Bash için hızlı başlangıç.

  • CLI başvuru komutlarını yerel olarak çalıştırmayı tercih ediyorsanız Azure CLI'yı yükleyin . Windows veya macOS üzerinde çalışıyorsanız Azure CLI’yi bir Docker kapsayıcısında çalıştırmayı değerlendirin. Daha fazla bilgi için bkz . Docker kapsayıcısında Azure CLI'yi çalıştırma.

    • Yerel yükleme kullanıyorsanız az login komutunu kullanarak Azure CLI ile oturum açın. Kimlik doğrulama işlemini tamamlamak için terminalinizde görüntülenen adımları izleyin. Diğer oturum açma seçenekleri için bkz . Azure CLI ile oturum açma.

    • İstendiğinde, ilk kullanımda Azure CLI uzantısını yükleyin. Uzantılar hakkında daha fazla bilgi için bkz. Azure CLI ile uzantıları kullanma.

    • Yüklü sürümü ve bağımlı kitaplıkları bulmak için az version komutunu çalıştırın. En son sürüme yükseltmek için az upgrade komutunu çalıştırın.

  • Bu makale 2.30 veya sonraki bir sürümü gerektirir. Sürümü bulmak için az --version komutunu çalıştırın. Yüklemeniz veya yükseltmeniz gerekirse, bkz. Azure CLI yükleme. Azure Cloud Shell kullanılıyorsa en son sürüm zaten yüklüdür.

Örnek betik

Azure Cloud Shell'i başlatma

Azure Cloud Shell, bu makaledeki adımları çalıştırmak için kullanabileceğiniz ücretsiz bir etkileşimli kabuktur. Yaygın Azure araçları, kabuğa önceden yüklenmiştir ve kabuk, hesabınızla birlikte kullanılacak şekilde yapılandırılmıştır.

Cloud Shell'i açmak için kod bloğunun sağ üst köşesinden Deneyin'i seçmeniz yeterlidir. İsterseniz https://shell.azure.com adresine giderek Cloud Shell'i ayrı bir tarayıcı sekmesinde de başlatabilirsiniz.

Cloud Shell açıldığında ortamınız için Bash'in seçili olduğunu doğrulayın. Sonraki oturumlarda Bash ortamında Azure CLI kullanılır, kod bloklarını kopyalamak için Kopyala'yı seçin, Cloud Shell'e yapıştırın ve çalıştırmak için Enter tuşuna basın.

Azure'da oturum açma

Cloud Shell'de oturum açılan ilk hesapta otomatik olarak kimlik doğrulaması yapılır. Farklı bir abonelik kullanarak oturum açmak için aşağıdaki betiği kullanın ve yerine <Subscription ID> Azure Abonelik Kimliğiniz yazın. Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

Daha fazla bilgi için bkz . Etkin aboneliği ayarlama veya etkileşimli olarak oturum açma

Betiği çalıştırın

# Throughput operations for a MongoDB API database and collection

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="throughput-mongodb-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-mongo-cosmos"
collection="collection1"
originalThroughput=400
updateThroughput=500

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for MongoDB API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --kind MongoDB

# Create a MongoDB API database
echo "Creating $database with $originalThroughput"
az cosmosdb mongodb database create --account-name $account --resource-group $resourceGroup --name $database --throughput $originalThroughput

# Define a minimal index policy for the collection
printf '[ {"key": {"keys": ["_id"]}} ]' > idxpolicy-$randomIdentifier.json

# Create a MongoDB API collection
az cosmosdb mongodb collection create --account-name $account --resource-group $resourceGroup --database-name $database --name $collection --shard "user_id" --throughput $originalThroughput --idx @idxpolicy-$randomIdentifier.json

# Clean up temporary index policy file
rm -f "idxpolicy-$randomIdentifier.json"

# Throughput operations for MongoDB API database
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned database throughput
az cosmosdb mongodb database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.throughput -o tsv

# Retrieve the minimum allowable database throughput
minimumThroughput=$(az cosmosdb mongodb database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.minimumThroughput -o tsv)
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update database throughput
echo "Updating $database throughput to $updateThroughput"
az cosmosdb mongodb database throughput update --account-name $account --resource-group $resourceGroup --name $database --throughput $updateThroughput

# Migrate the database from standard (manual) throughput to autoscale throughput
az cosmosdb mongodb database throughput migrate --account-name $account --resource-group $resourceGroup --name $database --throughput-type 'autoscale'

# Retrieve current autoscale provisioned max database throughput
az cosmosdb mongodb database throughput show --account-name $account --resource-group $resourceGroup --name $database --query resource.autoscaleSettings.maxThroughput -o tsv

# Throughput operations for MongoDB API collection
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned collection throughput
az cosmosdb mongodb collection throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $collection --query resource.throughput -o tsv

# Retrieve the minimum allowable collection throughput
minimumThroughput=$(az cosmosdb mongodb collection throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $collection --query resource.minimumThroughput -o tsv)

echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update collection throughput
echo "Updating collection throughput to $updateThroughput"
az cosmosdb mongodb collection throughput update --account-name $account --resource-group $resourceGroup --database-name $database --name $collection --throughput $updateThroughput

# Migrate the collection from standard (manual) throughput to autoscale throughput
az cosmosdb mongodb collection throughput migrate --account-name $account --resource-group $resourceGroup --database-name $database --name $collection --throughput 'autoscale'

# Retrieve the current autoscale provisioned max collection throughput
az cosmosdb mongodb collection throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $collection --query resource.autoscaleSettings.maxThroughput -o tsv

Kaynakları temizleme

Bu kaynaklara sürekli ihtiyaç duymadığınız sürece az group delete komutunu kullanarak kaynak grubunu ve onunla ilişkili tüm kaynakları kaldırmak için aşağıdaki komutu kullanın. Bu kaynaklardan bazılarının oluşturulması ve silinmesi biraz zaman alabilir.

az group delete --name $resourceGroup

Örnek başvuru

Bu betik aşağıdaki komutları kullanır. Tablodaki her komut, komuta özgü belgelere yönlendirir.

Command Notlar
az group create Tüm kaynakların depolandığı bir kaynak grubu oluşturur.
az cosmosdb create Azure Cosmos DB hesabı oluşturur.
az cosmosdb mongodb database create Azure Cosmos DB MongoDB API veritabanı oluşturur.
az cosmosdb mongodb collection create Azure Cosmos DB MongoDB API koleksiyonu oluşturur.
az cosmosdb mongodb veritabanı aktarım hızı güncelleştirmesi Azure Cosmos DB MongoDB API veritabanı için RU'ları güncelleştirme.
az cosmosdb mongodb collection aktarım hızı güncelleştirmesi Azure Cosmos DB MongoDB API koleksiyonu için RU'ları güncelleştirme.
az cosmosdb mongodb veritabanı aktarım hızı geçişi Veritabanı için aktarım hızını geçirme.
az cosmosdb mongodb collection aktarım hızı geçişi Bir koleksiyon için aktarım hızını geçirme.
az group delete Bir kaynak grubunu tüm iç içe geçmiş kaynaklar dahil siler.

Sonraki adımlar

Azure Cosmos DB CLI hakkında daha fazla bilgi için bkz . Azure Cosmos DB CLI belgeleri.