4

It's really neat that Azure Cosmos DB now also supports Aggregation Pipelines, and this makes it a viable replacement for us to use instead of running our own Mongo DB Containers, but I have failed to find a way to enable the features via code (how to do it in the Portal is described here: https://azure.microsoft.com/en-gb/blog/azure-cosmosdb-extends-support-for-mongodb-aggregation-pipeline-unique-indexes-and-more/).

We need this for the integration and testing environments which we create via deployment pipelines from scratch every day, and the backing Cosmos DB instances must support Aggregation pipelines.

I have checked the API documentation at https://learn.microsoft.com/en-us/rest/api/documentdb/, and also the az cosmosdb command line tool, but I can't find the right setting to pass in.

Has this just not yet surfaced, or am I missing something?

3
  • 2
    Currently, this functionality is only available via Azure Portal. Azure CLI support for enabling preview features will be added soon. I will share a link to the documentation once this is live Commented Dec 23, 2017 at 3:31
  • @SiddheshVethe OK, thanks. This would be a great thing to have. Commented Dec 27, 2017 at 7:41
  • Any news on this, @SiddheshVethe? This is getting annoying, unfortunately. Commented Jan 17, 2018 at 7:42

2 Answers 2

4

You can track the change with the following pull request: https://github.com/Azure/azure-cli/pull/5451#pullrequestreview-94854631

The following command will allow you to enable aggregation pipeline.

az cosmosdb update -n {acc} -g {rg} --capabilities EnableAggregationPipeline
Sign up to request clarification or add additional context in comments.

3 Comments

after i run this command i am getting following issue:Parameter 'resource_group_name' must conform to the following pattern: '^[-\\w\\._\(\)]+$'. Traceback (most recent call last): File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/knack/cli.py", line 197, in invoke cmd_result = self.invocation.execute(args) File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 369, in execute six.reraise(*sys.exc_info())....
Any chance there's a way to enable this with ARM? I try "capabilities": { "name": "EnableAggregationPipeline" } but it doesn't do anything.
You can also enable this feature via Azure portal. Go to Mongo Preview Features, you can see the option.
2

DON'T DO THIS - see accepted answer.

A colleague of mine found the following temporary solution for this problem, using a presumably undocumented API of Azure (this is a bash script). Pass in LOCATION, RESOURCE_GROUP and BM_ACCOUNT, and this script will create a Mongo API Cosmos DB account with enabled aggregation pipelines.

TOKEN=$(az account get-access-token | jq ".accessToken" | tr -d '"')

if [ -z "$LOCATION" ]; then
    export LOCATION="NorthEurope"
fi
echo "INFO [cosmos]: Using location: $LOCATION"
echo "INFO [cosmos]: Creating bookmarks DB"
BM_ACCOUNT="name-of-your-bookmark-db"
az cosmosdb create --resource-group $RESOURCE_GROUP \
    --name $BM_ACCOUNT \
    --kind MongoDB \
    --locations "$LOCATION=0"

curl -X PATCH \
     -H "Authorization: Bearer ${TOKEN}" \
     -H 'Content-Type: application/json' \
     --data '{"properties":{"capabilities":[{"name":"EnableAggregationPipeline","description":null}]}}' \
     "https://management.azure.com/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.DocumentDb/databaseAccounts/${BM_ACCOUNT}/?api-version=2015-04-08" 

WAIT_FOR=12
SUCCESS=0
while [ $WAIT_FOR -gt 0 ]; do
    sleep 10

    RESULT=$(curl -H "Authorization: Bearer ${TOKEN}" \
                  -H 'Content-Type: application/json' \
                  "https://management.azure.com/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.DocumentDb/databaseAccounts/${BM_ACCOUNT}/?api-version=2015-04-08" \
                  | jq ".properties.capabilities[].name" \
                  | tr -d '"')

    if [ "$RESULT" == "EnableAggregationPipeline" ]; then
        SUCCESS=1
        break;
    fi

    echo "INFO [cosmos]: Waiting another ${WAIT_FOR} tries for 'EnableAggregationPipeline' capability..."
    ((WAIT_FOR--))
done

if [ $SUCCESS -eq 0 ]; then
    echo "ERROR [cosmos]: Did not get required CosmosDB capability of 'EnableAggregationPipeline' in time for account ${BM_ACCOUNT} - giving up." >&2
    exit 1
fi

I perhaps wouldn't recommend using this for production purposes, but as far as we see, it actually works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.