Reputation: 1983
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?
Upvotes: 4
Views: 4694
Reputation: 1983
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.
Upvotes: 2
Reputation: 81
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
Upvotes: 4