Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
Last active July 16, 2018 14:36
Show Gist options
  • Save GuyHarwood/9b868b78ed37fdd149878254ea878415 to your computer and use it in GitHub Desktop.
Save GuyHarwood/9b868b78ed37fdd149878254ea878415 to your computer and use it in GitHub Desktop.
Create collections in CosmosDB from a list of json files in a directory. You can optionally use the json files to determine the expected schema of a document
#!/bin/bash
# exit on error
set -e
# input parameters
# $1 resource group to target
# $2 cosmosDB instance name
# Set variables for the new account, database, and collection
resourceGroupName=$1
cosmosInstanceName=$2
databaseName='mtc'
collectionThroughput=$3
# create database
az cosmosdb database create \
--name $cosmosInstanceName \
--db-name $databaseName \
--resource-group $resourceGroupName
# the following assumes you have json files in the following folder that match the collections being created
cd ./..//schemas/database
declare collections=$(ls -1 *.json | sed -e 's/\..*$//')
## now loop through the above array
for i in $collections
do
echo "creating collection $i with throughput of $collectionThroughput RUs"
az cosmosdb collection create \
--collection-name $i \
--name $cosmosInstanceName \
--db-name $databaseName \
--resource-group $resourceGroupName \
--throughput $collectionThroughput
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment