2

我想通过 AzureRM Powershell 以编程方式启用聚合管道和 MongoDBv3.4 预览功能。

在此处输入图像描述

到目前为止,我已经尝试通过 Azure ARM 模板和Set-AzureRmResource命令来做到这一点,但没有成功。

Set-AzureRmResource

$updateDBProperties = @{
        "capabilities" = @(@{"Name" = "EnableAggregationPipeline"}, @{"Name"= "MongoDBv3.4"}) 
};

# also tried without luck
# $updateDBProperties = @{
#       "capabilities" = @("EnableAggregationPipeline", "MongoDBv3.4")
# };

# won't work
Set-AzureRmResource -ResourceType "Microsoft.DocumentDb/databaseAccounts" `
    -ApiVersion "2015-04-08" `
    -ResourceGroupName "my-resource-group" `
    -Name "my-cosmosdb-development" `
    -Properties $updateDBProperties

通过没有运气的arm模板:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "cosmosDBName": {
    "type": "string"
    },
    "location": {
    "type": "string"
    },
    "locations": {
    "type": "array"
    }
},
"variables": {},
"resources": [
    {
    "name": "[parameters('cosmosDBName')]",
    "type": "Microsoft.DocumentDB/databaseAccounts",
    "apiVersion": "2015-04-08",
    "location": "[parameters('location')]",
    "kind": "MongoDB",
    "properties": {
        "consistencyPolicy": {
        "defaultConsistencyLevel": "Session",
        "maxIntervalInSeconds": 5,
        "maxStalenessPrefix": 100
        },
        "databaseAccountOfferType": "Standard",
        "locations": "[array(parameters('locations'))]",
        "capabilities": [
        {
            "name": "EnableAggregationPipeline"
        },
        {
            "name": "MongoDBv3.4"
        }
        ]
    }
    }
],
"outputs": {}
}

我们通过Powershell加载上面的arm模板。已创建 cosmos db,但未启用预览功能:

New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroup -TemplateFile $templateDirectory"/azureCosmosDB.json" -TemplateParameterObject $templateParameterObject -Name $templateParameterObject.cosmosDBName;
4

3 回答 3

2

我通过命令行工具成功设置了这些功能az

az cosmosdb update \
   --name my-resource-group \
   --resource-group my-cosmosdb-deployment \
   --capabilities "EnableAggregationPipeline" "MongoDBv3.4"

虽然花了几分钟。希望有帮助!

于 2018-12-04T14:09:50.193 回答
0

为了让它作为 ARM 模板的一部分工作,我不得不将apiVersion(在你的情况下为 2015-04-08)更改为更新的内容:

"apiVersion": "2019-08-01",

有关 apiVersion 的更多信息,您可以在此处查看 MS 文档。

但是,目前这似乎仅在最初创建启用该功能的 Cosmos DB 时才有效;到目前为止,我还没有找到在初始配置资源后启用它的方法。

于 2019-10-29T20:23:39.193 回答
0

这可以通过 PowerShell 通过修补CosmosDB 帐户资源来实现。关键是添加-UsePatchSemantics标志,Set-AzureRmResource以便它发出 HTTP PATCH 请求,而不是 HTTP PUT。

$db = Get-AzureRmResource -ResourceName "CosmosDB account name" -ResourceGroupName "RG name" | Where-Object -Property ResourceType -eq "Microsoft.DocumentDb/databaseAccounts"

# Enable some optional capabilities/features
$props = @{capabilities = @( @{name="EnableAggregationPipeline"}, @{name="MongoDBv3.4"})}

# Patch the resource with these settings
Set-AzureRmResource -ResourceId $db.ResourceId -ApiVersion "2015-04-08" -PropertyObject $props -UsePatchSemantics
于 2019-07-01T16:29:42.010 回答