【问题标题】:How To Enable Azure Cosmos DB Preview Features (aggregation pipeline and Mongodbv3.4) via Powershell?如何通过 Powershell 启用 Azure Cosmos DB 预览功能(聚合管道和 Mongodbv3.4)?
【发布时间】:2018-06-12 05:39:59
【问题描述】:

我想通过 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

通过手臂模板没有运气:

{
"$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;

【问题讨论】:

  • 你能在你的 mongo 数据库的资源浏览器中检查capabilities 吗?这两个属性是否存在?
  • @JoyWang 您的意思是在生成的自动化脚本(arm 模板)中?不,即使我运行了以上所有内容,它也不存在。
  • 我的意思是在执行你的命令之后,你可以在resources.azure.com 中检查你的mongo db 的功能,如果那里有两个name 属性?如果它们存在,我认为它是成功的。如果您检查门户中的按钮,它们未启用,这可能是一个错误,因为我在 web 应用程序中看到了类似的问题。
  • resources.azure.com 中不会生成这两个属性。它仅在我使用 Azure CLI 命令而不是 Powershell 的 AzureRM 时生成。

标签: powershell azure azure-cosmosdb azure-cosmosdb-mongoapi


【解决方案1】:

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

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

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

【讨论】:

  • 另一个预览功能的标签是“mongoEnableDocLevelTTL”...以防万一有人想启用所有三个
【解决方案2】:

这可以通过 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

【讨论】:

    【解决方案3】:

    为了让它作为 ARM 模板的一部分工作,我必须将 apiVersion(在您的情况下为 2015-04-08)更改为更新的版本:

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

    有关 apiVersion 的更多信息,您可以查看 MS 文档here

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 1970-01-01
      • 2022-12-17
      • 2021-12-01
      • 1970-01-01
      相关资源
      最近更新 更多