Azure Cosmos DB for MongoDB-erőforrások kezelése a Bicep használatával
A KÖVETKEZŐKRE VONATKOZIK: MongoDB
Ebből a cikkből megtudhatja, hogyan helyezheti üzembe és kezelheti Azure Cosmos DB-fiókjait a MongoDB-hez, adatbázisokhoz és gyűjteményekhez készült Azure Cosmos DB-fiókok a Bicep használatával.
Ez a cikk a MongoDB-fiókokhoz készült API Bicep-mintáit mutatja be. Bicep-mintákat is találhat az SQL, a Cassandra, a Gremlin és a Table API-khoz.
Fontos
- A fióknevek legfeljebb 44 karakter hosszúságúak, amelyek mindegyike kisbetűs.
- Az átviteli sebesség értékeinek módosításához telepítse újra a sablont frissített RU/s értékekkel.
- Ha helyeket ad hozzá vagy távolít el egy Azure Cosmos DB-fiókhoz, nem módosíthatja egyidejűleg a többi tulajdonságot. Ezeket a műveleteket külön kell elvégezni.
Az alábbi Azure Cosmos DB-erőforrások létrehozásához másolja a következő példát egy új bicep-fájlba. Igény szerint létrehozhat egy paraméterfájlt, amelyet akkor használhat, ha ugyanazon erőforrás több példányát helyezi üzembe különböző névvel és értékekkel. Az Azure Resource Manager-sablonok üzembe helyezésének számos módja van, például az Azure CLI, az Azure PowerShell és a Cloud Shell.
Api a MongoDB-hez automatikus skálázás kiosztott átviteli sebességgel
Ez a sablon létrehoz egy Azure Cosmos DB-fiókot a MongoDB API-hoz (3.2, 3.6, 4.0 vagy 4.2) két olyan gyűjteményrel, amelyek az adatbázis szintjén osztják meg az automatikus skálázási átviteli sebességet.
@description('Cosmos DB account name')
param accountName string = 'mongodb-${uniqueString(resourceGroup().id)}'
@description('Location for the Cosmos DB account.')
param location string = resourceGroup().location
@description('The primary replica region for the Cosmos DB account.')
param primaryRegion string
@description('The secondary replica region for the Cosmos DB account.')
param secondaryRegion string
@description('Specifies the MongoDB server version to use.')
@allowed([
'3.2'
'3.6'
'4.0'
'4.2'
])
param serverVersion string = '4.2'
@description('The default consistency level of the Cosmos DB account.')
@allowed([
'Eventual'
'ConsistentPrefix'
'Session'
'BoundedStaleness'
'Strong'
])
param defaultConsistencyLevel string = 'Eventual'
@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.')
@minValue(10)
@maxValue(2147483647)
param maxStalenessPrefix int = 100000
@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.')
@minValue(5)
@maxValue(86400)
param maxIntervalInSeconds int = 300
@description('The name for the Mongo DB database')
param databaseName string
@description('Maximum autoscale throughput for the database shared with up to 25 collections')
@minValue(1000)
@maxValue(1000000)
param sharedAutoscaleMaxThroughput int = 1000
@description('The name for the first Mongo DB collection')
param collection1Name string
@description('The name for the second Mongo DB collection')
param collection2Name string
@description('Maximum dedicated autoscale throughput for the orders collection')
@minValue(1000)
@maxValue(1000000)
param dedicatedAutoscaleMaxThroughput int = 1000
var consistencyPolicy = {
Eventual: {
defaultConsistencyLevel: 'Eventual'
}
ConsistentPrefix: {
defaultConsistencyLevel: 'ConsistentPrefix'
}
Session: {
defaultConsistencyLevel: 'Session'
}
BoundedStaleness: {
defaultConsistencyLevel: 'BoundedStaleness'
maxStalenessPrefix: maxStalenessPrefix
maxIntervalInSeconds: maxIntervalInSeconds
}
Strong: {
defaultConsistencyLevel: 'Strong'
}
}
var locations = [
{
locationName: primaryRegion
failoverPriority: 0
isZoneRedundant: false
}
{
locationName: secondaryRegion
failoverPriority: 1
isZoneRedundant: false
}
]
resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
name: toLower(accountName)
location: location
kind: 'MongoDB'
properties: {
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: locations
databaseAccountOfferType: 'Standard'
enableAutomaticFailover: true
apiProperties: {
serverVersion: serverVersion
}
capabilities: [
{
name: 'DisableRateLimitingResponses'
}
]
}
}
resource database 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2022-05-15' = {
parent: account
name: databaseName
properties: {
resource: {
id: databaseName
}
options: {
autoscaleSettings: {
maxThroughput: sharedAutoscaleMaxThroughput
}
}
}
}
resource collection1 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
parent: database
name: collection1Name
properties: {
resource: {
id: collection1Name
shardKey: {
user_id: 'Hash'
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
{
key: {
keys: [
'$**'
]
}
}
{
key: {
keys: [
'product_name'
'product_category_name'
]
}
}
]
}
}
}
resource collection2 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
parent: database
name: collection2Name
properties: {
resource: {
id: collection2Name
shardKey: {
company_id: 'Hash'
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
{
key: {
keys: [
'$**'
]
}
}
{
key: {
keys: [
'customer_id'
'order_id'
]
}
}
]
}
options: {
autoscaleSettings: {
maxThroughput: dedicatedAutoscaleMaxThroughput
}
}
}
}
Api a MongoDB-hez standard kiosztott átviteli sebességgel
Hozzon létre egy Azure Cosmos DB-fiókot a MongoDB API-hoz (3.2, 3.6, 4.0 vagy 4.2) két gyűjteménysel, amelyek adatbázisszinten 400 RU/s standard (manuális) átviteli sebességgel osztoznak.
@description('Cosmos DB account name')
param accountName string = 'mongodb-${uniqueString(resourceGroup().id)}'
@description('Location for the Cosmos DB account.')
param location string = resourceGroup().location
@description('The primary replica region for the Cosmos DB account.')
param primaryRegion string
@description('The secondary replica region for the Cosmos DB account.')
param secondaryRegion string
@allowed([
'Eventual'
'ConsistentPrefix'
'Session'
'BoundedStaleness'
'Strong'
])
@description('The default consistency level of the Cosmos DB account.')
param defaultConsistencyLevel string = 'Eventual'
@allowed([
'3.2'
'3.6'
'4.0'
'4.2'
])
@description('Specifies the MongoDB server version to use.')
param serverVersion string = '4.2'
@minValue(10)
@maxValue(2147483647)
@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.')
param maxStalenessPrefix int = 100000
@minValue(5)
@maxValue(86400)
@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.')
param maxIntervalInSeconds int = 300
@description('The name for the Mongo DB database')
param databaseName string
@minValue(400)
@maxValue(1000000)
@description('The shared throughput for the Mongo DB database, up to 25 collections')
param sharedThroughput int = 400
@description('The name for the first Mongo DB collection')
param collection1Name string
@description('The name for the second Mongo DB collection')
param collection2Name string
@minValue(400)
@maxValue(1000000)
@description('The dedicated throughput for the orders collection')
param dedicatedThroughput int = 400
var consistencyPolicy = {
Eventual: {
defaultConsistencyLevel: 'Eventual'
}
ConsistentPrefix: {
defaultConsistencyLevel: 'ConsistentPrefix'
}
Session: {
defaultConsistencyLevel: 'Session'
}
BoundedStaleness: {
defaultConsistencyLevel: 'BoundedStaleness'
maxStalenessPrefix: maxStalenessPrefix
maxIntervalInSeconds: maxIntervalInSeconds
}
Strong: {
defaultConsistencyLevel: 'Strong'
}
}
var locations = [
{
locationName: primaryRegion
failoverPriority: 0
isZoneRedundant: false
}
{
locationName: secondaryRegion
failoverPriority: 1
isZoneRedundant: false
}
]
resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
name: toLower(accountName)
location: location
kind: 'MongoDB'
properties: {
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: locations
databaseAccountOfferType: 'Standard'
enableAutomaticFailover: true
apiProperties: {
serverVersion: serverVersion
}
capabilities: [
{
name: 'DisableRateLimitingResponses'
}
]
}
}
resource database 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2022-05-15' = {
parent: account
name: databaseName
properties: {
resource: {
id: databaseName
}
options: {
throughput: sharedThroughput
}
}
}
resource collection1 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
parent: database
name: collection1Name
properties: {
resource: {
id: collection1Name
shardKey: {
user_id: 'Hash'
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
{
key: {
keys: [
'$**'
]
}
}
{
key: {
keys: [
'product_name'
'product_category_name'
]
}
}
]
}
}
}
resource collection2 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
parent: database
name: collection2Name
properties: {
resource: {
id: collection2Name
shardKey: {
company_id: 'Hash'
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
{
key: {
keys: [
'$**'
]
}
}
{
key: {
keys: [
'customer_id'
'order_id'
]
}
}
]
}
options: {
throughput: dedicatedThroughput
}
}
}
Következő lépések
Íme néhány további erőforrás:
- A Bicep dokumentációja
- A Bicep-eszközök telepítése
- Kapacitástervezést szeretne végezni az Azure Cosmos DB-be való migráláshoz? A kapacitástervezéshez használhatja a meglévő adatbázisfürt adatait.
- Ha csak annyit tud, hogy hány virtuális mag és kiszolgáló található a meglévő adatbázisfürtben, olvassa el a kérelemegységek becslését virtuális magok vagy vCPU-k használatával
- Ha ismeri az aktuális adatbázis számítási feladataira vonatkozó tipikus kérési arányokat, olvassa el a kérelemegységek becslését az Azure Cosmos DB kapacitástervezővel