Megosztás a következőn keresztül:


Az Azure Cosmos DB for NoSQL-erőforrások kezelése a PowerShell használatával

A KÖVETKEZŐRE VONATKOZIK: NoSQL

Az alábbi útmutató bemutatja, hogyan használható a PowerShell az Azure Cosmos DB for NoSQL-erőforrások, köztük az Azure Cosmos DB-fiók, az adatbázis, a tároló és az átviteli sebesség felügyeletének szkriptelésére és automatizálására. Más API-kHoz készült PowerShell-parancsmagokért lásd : PowerShell-minták a Cassandra-hoz, PowerShell-minták a MongoDB API-hoz, PowerShell-minták a Gremlinhez, PowerShell-minták táblázathoz

Feljegyzés

A cikkben szereplő minták Az.CosmosDB felügyeleti parancsmagokat használnak. A legújabb módosításokért tekintse meg az Az.CosmosDB API referenciaoldalát.

Az Azure Cosmos DB platformfüggetlen kezeléséhez használhatja a parancsmagokat platformfüggetlen Az.CosmosDB PowerShell-lel, valamint az Azure CLI-t, a REST API-t vagy az Azure Portalt.Az

Feljegyzés

Javasoljuk, hogy az Azure Az PowerShell modult használja az Azure-ral való interakcióhoz. Az első lépésekhez tekintse meg Az Azure PowerShell telepítése témakört. Az Az PowerShell-modulra történő migrálás részleteiről lásd: Az Azure PowerShell migrálása az AzureRM modulból az Az modulba.

Első lépések

Kövesse az Azure PowerShell telepítését és konfigurálását az Azure-fiók PowerShellben való telepítéséhez és konfigurálásához.

Fontos

Az Azure Cosmos DB-erőforrások nem nevezhetők át, mivel ez sérti az Azure Resource Manager erőforrás-URI-kkal való működését.

Azure Cosmos DB-fiókok

Az alábbi szakaszok bemutatják, hogyan kezelheti az Azure Cosmos DB-fiókot, többek között az alábbiakat:

Azure Cosmos DB-fiók létrehozása

Ez a parancs létrehoz egy Azure Cosmos DB-adatbázisfiókot több régióval, szolgáltatás által felügyelt feladatátvételi és kötött-elavultsági konzisztenciaszabályzattal.

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$apiKind = "Sql"
$consistencyLevel = "BoundedStaleness"
$maxStalenessInterval = 300
$maxStalenessPrefix = 100000
$locations = @()
$locations += New-AzCosmosDBLocationObject -LocationName "East US" -FailoverPriority 0 -IsZoneRedundant 0
$locations += New-AzCosmosDBLocationObject -LocationName "West US" -FailoverPriority 1 -IsZoneRedundant 0

New-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -LocationObject $locations `
    -Name $accountName `
    -ApiKind $apiKind `
    -EnableAutomaticFailover:$true `
    -DefaultConsistencyLevel $consistencyLevel `
    -MaxStalenessIntervalInSeconds $maxStalenessInterval `
    -MaxStalenessPrefix $maxStalenessPrefix
  • $resourceGroupName Az Azure-erőforráscsoport, amelybe telepíteni szeretné az Azure Cosmos DB-fiókot. Már léteznie kell.
  • $locations Az adatbázisfiók régiói, a régió pedig FailoverPriority 0 az írási régió.
  • $accountName Az Azure Cosmos DB-fiók neve. Egyedinek kell lennie, kisbetűsnek kell lennie, csak alfanumerikus és "-" karaktereket kell tartalmaznia, és 3 és 31 karakter közötti hosszúságúnak kell lennie.
  • $apiKind A létrehozandó Azure Cosmos DB-fiók típusa. További információ: API-k az Azure Cosmos DB-ben.
  • $consistencyPolicy, $maxStalenessIntervalés $maxStalenessPrefix az Azure Cosmos DB-fiók alapértelmezett konzisztenciaszintje és beállításai. További információ: Konzisztenciaszintek az Azure Cosmos DB-ben.

Az Azure Cosmos DB-fiókok konfigurálhatók IP-tűzfallal, virtuális hálózati szolgáltatásvégpontokkal és privát végpontokkal. Az Azure Cosmos DB IP-tűzfalának konfigurálásáról további információt az IP-tűzfal konfigurálása című témakörben talál. Az Azure Cosmos DB szolgáltatásvégpontjainak engedélyezéséről további információt a virtuális hálózatokról való hozzáférés konfigurálása című témakörben talál. További információ a privát végpontok Azure Cosmos DB-hez való engedélyezéséről: Hozzáférés konfigurálása privát végpontokról.

Az összes Azure Cosmos DB-fiók listázása erőforráscsoportban

Ez a parancs egy erőforráscsoport összes Azure Cosmos DB-fiókját felsorolja.

$resourceGroupName = "myResourceGroup"

Get-AzCosmosDBAccount -ResourceGroupName $resourceGroupName

Azure Cosmos DB-fiók tulajdonságainak lekérése

Ezzel a paranccsal lekérheti egy meglévő Azure Cosmos DB-fiók tulajdonságait.

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"

Get-AzCosmosDBAccount -ResourceGroupName $resourceGroupName -Name $accountName

Azure Cosmos DB-fiók frissítése

Ez a parancs lehetővé teszi az Azure Cosmos DB-adatbázisfiók tulajdonságainak frissítését. A frissíthető tulajdonságok a következők:

  • Régiók hozzáadása vagy eltávolítása
  • Az alapértelmezett konzisztenciaházirend módosítása
  • IP-tartományszűrő módosítása
  • Virtuális hálózati konfigurációk módosítása
  • Többrégiós írások engedélyezése

Feljegyzés

Nem adhat hozzá vagy távolíthat el régiókat (locations) és nem módosíthatja az Azure Cosmos DB-fiókok egyéb tulajdonságait. A régiókat külön műveletként kell végrehajtani a fiók bármely más módosításától.

Feljegyzés

Ez a parancs lehetővé teszi régiók hozzáadását és eltávolítását, de nem teszi lehetővé a feladatátvételi prioritások módosítását vagy manuális feladatátvétel indítását. Lásd: Feladatátvételi prioritás módosítása és manuális feladatátvétel aktiválása.

Tipp.

Új régió hozzáadásakor az összes adatot teljes körűen replikálni és véglegesíteni kell az új régióban, mivel a régiót csak ezt követően lehet elérhetőként megjelölni. A művelet időtartama attól függ, hogy mennyi adatot tárol a fiók. Ha az aszinkron átviteli sebesség skálázási művelete folyamatban van, az átviteli sebesség felskálázási művelete szünetel, és automatikusan folytatódik, amikor a régió hozzáadása/eltávolítása művelet befejeződött.

# Create account with two regions
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$apiKind = "Sql"
$consistencyLevel = "Session"
$enableAutomaticFailover = $true
$locations = @()
$locations += New-AzCosmosDBLocationObject -LocationName "East US" -FailoverPriority 0 -IsZoneRedundant 0
$locations += New-AzCosmosDBLocationObject -LocationName "West US" -FailoverPriority 1 -IsZoneRedundant 0

# Create the Azure Cosmos DB account
New-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -LocationObject $locations `
    -Name $accountName `
    -ApiKind $apiKind `
    -EnableAutomaticFailover:$enableAutomaticFailover `
    -DefaultConsistencyLevel $consistencyLevel

# Add a region to the account
$locationObject2 = @()
$locationObject2 += New-AzCosmosDBLocationObject -LocationName "East US" -FailoverPriority 0 -IsZoneRedundant 0
$locationObject2 += New-AzCosmosDBLocationObject -LocationName "West US" -FailoverPriority 1 -IsZoneRedundant 0
$locationObject2 += New-AzCosmosDBLocationObject -LocationName "South Central US" -FailoverPriority 2 -IsZoneRedundant 0

Update-AzCosmosDBAccountRegion `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -LocationObject $locationObject2

Write-Host "Update-AzCosmosDBAccountRegion returns before the region update is complete."
Write-Host "Check account in Azure portal or using Get-AzCosmosDBAccount for region status."
Write-Host "When region was added, press any key to continue."
$HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | OUT-NULL
$HOST.UI.RawUI.Flushinputbuffer()

# Remove West US region from the account
$locationObject3 = @()
$locationObject3 += New-AzCosmosDBLocationObject -LocationName "East US" -FailoverPriority 0 -IsZoneRedundant 0
$locationObject3 += New-AzCosmosDBLocationObject -LocationName "South Central US" -FailoverPriority 1 -IsZoneRedundant 0

Update-AzCosmosDBAccountRegion `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -LocationObject $locationObject3

Write-Host "Update-AzCosmosDBAccountRegion returns before the region update is complete."
Write-Host "Check account in Azure portal or using Get-AzCosmosDBAccount for region status."

Több írási régió engedélyezése Azure Cosmos DB-fiókhoz

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$enableAutomaticFailover = $false
$enableMultiMaster = $true

# First disable service-managed failover - cannot have both service-managed
# failover and multi-region writes on an account
Update-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -EnableAutomaticFailover:$enableAutomaticFailover

# Now enable multi-region writes
Update-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -EnableMultipleWriteLocations:$enableMultiMaster

Azure Cosmos DB-fiók törlése

Ez a parancs töröl egy meglévő Azure Cosmos DB-fiókot.

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"

Remove-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -PassThru:$true

Azure Cosmos DB-fiók címkéinek frissítése

Ez a parancs beállítja az Azure Cosmos DB-fiók Azure-erőforráscímkéket . A címkék a fióklétrehozáskor New-AzCosmosDBAccount és a fiókfrissítéskor is beállíthatók a használatával Update-AzCosmosDBAccount.

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$tags = @{dept = "Finance"; environment = "Production";}

Update-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -Tag $tags

Szolgáltatás által felügyelt feladatátvétel engedélyezése

Az alábbi parancs beállít egy Azure Cosmos DB-fiókot egy szolgáltatás által felügyelt feladatátvétel végrehajtására a másodlagos régióba, ha az elsődleges régió elérhetetlenné válik.

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$enableAutomaticFailover = $true
$enableMultiMaster = $false

# First disable multi-region writes - cannot have both automatic
# failover and multi-region writes on an account
Update-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -EnableMultipleWriteLocations:$enableMultiMaster

# Now enable service-managed failover
Update-AzCosmosDBAccount `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -EnableAutomaticFailover:$enableAutomaticFailover

Feladatátvételi prioritás módosítása

A szolgáltatás által felügyelt feladatátvétellel konfigurált fiókok esetében módosíthatja azt a sorrendet, amelyben az Azure Cosmos DB előlépteti a másodlagos replikákat az elsődlegesre, ha az elsődleges nem érhető el.

Az alábbi példában feltételezzük, hogy az aktuális feladatátvételi prioritás a West US = 0, East US = 1. South Central US = 2 A parancs ezt a következőre módosítja: West US = 0, South Central US = 1. East US = 2

Figyelemfelhívás

A hely failoverPriority=0 módosítása manuális feladatátvételt indít el egy Azure Cosmos DB-fiókhoz. Az egyéb prioritási módosítások nem indítják el a feladatátvételt.

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$locations = @("West US", "South Central US", "East US") # Regions ordered by UPDATED failover priority

Update-AzCosmosDBAccountFailoverPriority `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -FailoverPolicy $locations

Trigger manuális feladatátvétele

A manuális feladatátvétellel konfigurált fiókok esetében a feladatátvételt és a másodlagos replikák elsődlegesre való előléptetését a következő módosítással végezheti el failoverPriority=0: Ezzel a művelettel vészhelyreállítási próbát kezdeményezhet a vészhelyreállítás tervezésének teszteléséhez.

Az alábbi példában tegyük fel, hogy a fiók aktuális feladatátvételi prioritással rendelkezik West US = 0 , és East US = 1 megfordítja a régiókat.

Figyelemfelhívás

failoverPriority=0 A módosítás locationName manuális feladatátvételt indít el egy Azure Cosmos DB-fiókhoz. A többi prioritás módosítása nem indítja el a feladatátvételt.

Feljegyzés

Ha manuális feladatátvételi műveletet hajt végre, miközben az aszinkron átviteli sebesség skálázási művelete folyamatban van, az átviteli sebesség felskálázási művelete szünetel. A feladatátvételi művelet befejeződésekor automatikusan folytatódik.

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$locations = @("East US", "West US") # Regions ordered by UPDATED failover priority

Update-AzCosmosDBAccountFailoverPriority `
    -ResourceGroupName $resourceGroupName `
    -Name $accountName `
    -FailoverPolicy $locations

Erőforrás-zárolások listázása Egy Azure Cosmos DB-fiókon

Az erőforrás-zárolások elhelyezhetők az Azure Cosmos DB-erőforrásokon, beleértve az adatbázisokat és a gyűjteményeket is. Az alábbi példa bemutatja, hogyan listázhatja az Azure Cosmos DB-fiók összes Azure-erőforrás-zárolását.

$resourceGroupName = "myResourceGroup"
$resourceTypeAccount = "Microsoft.DocumentDB/databaseAccounts"
$accountName = "mycosmosaccount"

Get-AzResourceLock `
    -ResourceGroupName $resourceGroupName `
    -ResourceType $resourceTypeAccount `
    -ResourceName $accountName

Azure Cosmos DB Database

A következő szakaszok bemutatják, hogyan kezelheti az Azure Cosmos DB-adatbázist, beleértve a következőket:

Létrehoz egy Azure Cosmos DB-adatbázist

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"

New-AzCosmosDBSqlDatabase `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -Name $databaseName

Azure Cosmos DB-adatbázis létrehozása megosztott átviteli sebességgel

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$databaseRUs = 400

New-AzCosmosDBSqlDatabase `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -Name $databaseName `
    -Throughput $databaseRUs

Azure Cosmos DB-adatbázis átviteli sebességének lekérése

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"

Get-AzCosmosDBSqlDatabaseThroughput `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -Name $databaseName

Adatbázis átviteli sebességének migrálása automatikus skálázásra

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"

Invoke-AzCosmosDBSqlDatabaseThroughputMigration `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -Name $databaseName `
    -ThroughputType Autoscale

Az összes Azure Cosmos DB-adatbázis lekérése egy fiókban

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"

Get-AzCosmosDBSqlDatabase `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName

Egyetlen Azure Cosmos DB-adatbázis lekérése

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"

Get-AzCosmosDBSqlDatabase `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -Name $databaseName

Azure Cosmos DB-adatbázis törlése

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"

Remove-AzCosmosDBSqlDatabase `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -Name $databaseName

Erőforrás-zárolás létrehozása azure Cosmos DB-adatbázison a törlés megakadályozása érdekében

$resourceGroupName = "myResourceGroup"
$resourceType = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$resourceName = "$accountName/$databaseName"
$lockName = "myResourceLock"
$lockLevel = "CanNotDelete"

New-AzResourceLock `
    -ResourceGroupName $resourceGroupName `
    -ResourceType $resourceType `
    -ResourceName $resourceName `
    -LockName $lockName `
    -LockLevel $lockLevel

Erőforrás-zárolás eltávolítása egy Azure Cosmos DB-adatbázisban

$resourceGroupName = "myResourceGroup"
$resourceType = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$resourceName = "$accountName/$databaseName"
$lockName = "myResourceLock"

Remove-AzResourceLock `
    -ResourceGroupName $resourceGroupName `
    -ResourceType $resourceType `
    -ResourceName $resourceName `
    -LockName $lockName

Azure Cosmos DB-tároló

Az alábbi szakaszok bemutatják, hogyan kezelheti az Azure Cosmos DB-tárolót, beleértve a következőket:

Azure Cosmos DB-tároló létrehozása

# Create an Azure Cosmos DB container with default indexes and throughput at 400 RU
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"
$throughput = 400 #minimum = 400

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -Throughput $throughput

Azure Cosmos DB-tároló létrehozása automatikus skálázással

# Create an Azure Cosmos DB container with default indexes and autoscale throughput at 4000 RU
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"
$autoscaleMaxThroughput = 4000 #minimum = 4000

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -AutoscaleMaxThroughput $autoscaleMaxThroughput

Azure Cosmos DB-tároló létrehozása nagy partíciókulcs-mérettel

# Create an Azure Cosmos DB container with a large partition key value (version = 2)
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -PartitionKeyVersion 2

Azure Cosmos DB-tároló átviteli sebességének lekérése

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"

Get-AzCosmosDBSqlContainerThroughput `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName

Tároló átviteli sebességének áttelepítése automatikus skálázásra

$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"

Invoke-AzCosmosDBSqlContainerThroughputMigration `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -ThroughputType Autoscale

Azure Cosmos DB-tároló létrehozása egyéni indexszabályzattal

# Create a container with a custom indexing policy
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"
$indexPathIncluded = "/*"
$indexPathExcluded = "/myExcludedPath/*"

$includedPathIndex = New-AzCosmosDBSqlIncludedPathIndex -DataType String -Kind Range
$includedPath = New-AzCosmosDBSqlIncludedPath -Path $indexPathIncluded -Index $includedPathIndex

$indexingPolicy = New-AzCosmosDBSqlIndexingPolicy `
    -IncludedPath $includedPath `
    -ExcludedPath $indexPathExcluded `
    -IndexingMode Consistent `
    -Automatic $true

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -IndexingPolicy $indexingPolicy

Azure Cosmos DB-tároló létrehozása az indexelés kikapcsolásával

# Create an Azure Cosmos DB container with no indexing
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"

$indexingPolicy = New-AzCosmosDBSqlIndexingPolicy `
    -IndexingMode None

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -IndexingPolicy $indexingPolicy

Azure Cosmos DB-tároló létrehozása egyedi kulcsszabályzattal és TTL-vel

# Create a container with a unique key policy and TTL of one day
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"
$uniqueKeyPath = "/myUniqueKeyPath"
$ttlInSeconds = 86400 # Set this to -1 (or don't use it at all) to never expire

$uniqueKey = New-AzCosmosDBSqlUniqueKey `
    -Path $uniqueKeyPath

$uniqueKeyPolicy = New-AzCosmosDBSqlUniqueKeyPolicy `
    -UniqueKey $uniqueKey

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -UniqueKeyPolicy $uniqueKeyPolicy `
    -TtlInSeconds $ttlInSeconds

Azure Cosmos DB-tároló létrehozása ütközésfeloldással

Ha az összes ütközést a ConflictsFeedbe szeretné írni, és külön kezelni szeretné, adja át -Type "Custom" -Path "".

# Create container with last-writer-wins conflict resolution policy
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"
$conflictResolutionPath = "/myResolutionPath"

$conflictResolutionPolicy = New-AzCosmosDBSqlConflictResolutionPolicy `
    -Type LastWriterWins `
    -Path $conflictResolutionPath

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -ConflictResolutionPolicy $conflictResolutionPolicy

Ha egy tárolt eljárás használatához ütközésfeloldási szabályzatot szeretne létrehozni, hívja meg New-AzCosmosDBSqlConflictResolutionPolicy és adja át a paramétereket -Type és -ConflictResolutionProcedurea .

# Create container with custom conflict resolution policy using a stored procedure
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$partitionKeyPath = "/myPartitionKey"
$conflictResolutionSprocName = "mysproc"

$conflictResolutionSproc = "/dbs/$databaseName/colls/$containerName/sprocs/$conflictResolutionSprocName"

$conflictResolutionPolicy = New-AzCosmosDBSqlConflictResolutionPolicy `
    -Type Custom `
    -ConflictResolutionProcedure $conflictResolutionSproc

New-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName `
    -PartitionKeyKind Hash `
    -PartitionKeyPath $partitionKeyPath `
    -ConflictResolutionPolicy $conflictResolutionPolicy

Az összes Azure Cosmos DB-tároló listázása egy adatbázisban

# List all Azure Cosmos DB containers in a database
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"

Get-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName

Egyetlen Azure Cosmos DB-tároló lekérése egy adatbázisban

# Get a single Azure Cosmos DB container in a database
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"

Get-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName

Azure Cosmos DB-tároló törlése

# Delete an Azure Cosmos DB container
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"

Remove-AzCosmosDBSqlContainer `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName `
    -DatabaseName $databaseName `
    -Name $containerName

Erőforrás-zárolás létrehozása egy Azure Cosmos DB-tárolón a törlés megakadályozása érdekében

$resourceGroupName = "myResourceGroup"
$resourceType = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$resourceName = "$accountName/$databaseName/$containerName"
$lockName = "myResourceLock"
$lockLevel = "CanNotDelete"

New-AzResourceLock `
    -ResourceGroupName $resourceGroupName `
    -ResourceType $resourceType `
    -ResourceName $resourceName `
    -LockName $lockName `
    -LockLevel $lockLevel

Erőforrás-zárolás eltávolítása egy Azure Cosmos DB-tárolón

$resourceGroupName = "myResourceGroup"
$resourceType = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers"
$accountName = "mycosmosaccount"
$databaseName = "myDatabase"
$containerName = "myContainer"
$resourceName = "$accountName/$databaseName/$containerName"
$lockName = "myResourceLock"

Remove-AzResourceLock `
    -ResourceGroupName $resourceGroupName `
    -ResourceType $resourceType `
    -ResourceName $resourceName `
    -LockName $lockName

Következő lépések