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.