2

I would like to enable Aggregation Pipeline and MongoDBv3.4 preview features programmatically through AzureRM Powershell.

enter image description here

So far I've tried to do that through Azure ARM Template and Set-AzureRmResource command without any success.

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

Through arm template without luck:

{
"$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": {}
}

We load the arm template above through Powershell. The cosmos db get created but the preview features is not enabled:

New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroup -TemplateFile $templateDirectory"/azureCosmosDB.json" -TemplateParameterObject $templateParameterObject -Name $templateParameterObject.cosmosDBName;
Yudhistira Arya
  • 3,491
  • 6
  • 25
  • 42
  • Could you check the `capabilities` in the resource explorer of your mongo db? The two properties existing or not? – Joy Wang Jun 12 '18 at 06:45
  • @JoyWang you mean inside the generated automation script (arm template)? No it's not there even after I ran all of the above. – Yudhistira Arya Jun 13 '18 at 12:17
  • I mean after executing your command, you could check the capabilities of your mongo db in the `resources.azure.com`, if there are the two `name` properties over there? If they exist, I think it is successful. if you check the button in the portal, they are not enabled, it may be a bug, because I have seen a similar issue in web app. – Joy Wang Jun 14 '18 at 01:18
  • Those two properties are not generated in the resources.azure.com. It's only generated when I'm using Azure CLI command but not Powershell's AzureRM. – Yudhistira Arya Jun 27 '18 at 16:33

3 Answers3

2

I succeeded to set these capabilities via the command line tool az:

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

Though it took several minutes. Hope that helps!

0

This is achievable with PowerShell by patching the CosmosDB account resource. The key is to add the -UsePatchSemantics flag to Set-AzureRmResource so that it makes an HTTP PATCH request, rather than an 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
Brian Golden
  • 148
  • 6
0

To get this working as part of the ARM template, I had to change the apiVersion (2015-04-08, in your case) to something more recent:

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

For more information on apiVersion, you can review the MS documentation here.

However, this currently seems to only be working when initially creating the Cosmos DB with the feature enabled; So far, I didn't find a way to enable it after the resource has been initially provisioned.