diff --git a/101-cosmosdb-mongodb/README.md b/101-cosmosdb-mongodb/README.md new file mode 100644 index 000000000000..2a7d823491cd --- /dev/null +++ b/101-cosmosdb-mongodb/README.md @@ -0,0 +1,21 @@ +# Create an Azure Cosmos account for MongoDB API with two collections + +This template creates an Azure Cosmos account for MongoDB API, provisioned for two regions, then provision a database with throughput shared across 2 collections. + +Below are the parameters which can be user configured in the parameters file including: + +- **Consistency Level:** Select from one of the 5 consistency levels: Strong, Bounded Staleness, Session, Consistent Prefix, Eventual. +- **Multi-Region:** Enter locations for primary and secondary regions. +- **Multi-Master:** Select whether to enable multi-master support making both regions fully writable. +- **Automatic Failover:** Select whether to enable automatic failover on the account (Ignored when Multi-Master is enabled). +- **Database Name:** Enter the database name for the account. +- **Throughput:** Enter the Ru/s to share across the 2 containers (default is 400). +- **Collection 1 Name:** Enter the name for the first collection. +- **Collection 2 Name:** Enter the name for the second collection. + + + + + + + diff --git a/101-cosmosdb-mongodb/azuredeploy.json b/101-cosmosdb-mongodb/azuredeploy.json new file mode 100644 index 000000000000..8bfe62f97139 --- /dev/null +++ b/101-cosmosdb-mongodb/azuredeploy.json @@ -0,0 +1,206 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "accountName": { + "type": "string", + "defaultValue": "[concat('mongodb-', uniqueString(resourceGroup().id))]", + "metadata": { + "description": "Cosmos DB account name" + } + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]", + "metadata": { + "description": "Location for the Cosmos DB account." + } + }, + "primaryRegion":{ + "type":"string", + "metadata": { + "description": "The primary replica region for the Cosmos DB account." + } + }, + "secondaryRegion":{ + "type":"string", + "metadata": { + "description": "The secondary replica region for the Cosmos DB account." + } + }, + "defaultConsistencyLevel": { + "type": "string", + "defaultValue": "Session", + "allowedValues": [ "Eventual", "ConsistentPrefix", "Session", "BoundedStaleness", "Strong" ], + "metadata": { + "description": "The default consistency level of the Cosmos DB account." + } + }, + "maxStalenessPrefix": { + "type": "int", + "defaultValue": 100000, + "minValue": 10, + "maxValue": 2147483647, + "metadata": { + "description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000." + } + }, + "maxIntervalInSeconds": { + "type": "int", + "defaultValue": 300, + "minValue": 5, + "maxValue": 86400, + "metadata": { + "description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400." + } + }, + "multipleWriteLocations": { + "type": "bool", + "defaultValue": true, + "allowedValues": [ true, false ], + "metadata": { + "description": "Enable multi-master to make all regions writable." + } + }, + "databaseName": { + "type": "string", + "metadata": { + "description": "The name for the Mongo DB database" + } + }, + "throughput": { + "type": "int", + "defaultValue": 400, + "minValue": 400, + "maxValue": 1000000, + "metadata": { + "description": "The throughput for the Mongo DB database" + } + }, + "collection1Name": { + "type": "string", + "metadata": { + "description": "The name for the first Mongo DB collection" + } + }, + "collection2Name": { + "type": "string", + "metadata": { + "description": "The name for the second Mongo DB collection" + } + } + }, + "variables": { + "accountName": "[toLower(parameters('accountName'))]", + "consistencyPolicy": { + "Eventual": { + "defaultConsistencyLevel": "Eventual" + }, + "ConsistentPrefix": { + "defaultConsistencyLevel": "ConsistentPrefix" + }, + "Session": { + "defaultConsistencyLevel": "Session" + }, + "BoundedStaleness": { + "defaultConsistencyLevel": "BoundedStaleness", + "maxStalenessPrefix": "[parameters('maxStalenessPrefix')]", + "maxIntervalInSeconds": "[parameters('maxIntervalInSeconds')]" + }, + "Strong": { + "defaultConsistencyLevel": "Strong" + } + }, + "locations": + [ + { + "locationName": "[parameters('primaryRegion')]", + "failoverPriority": 0 + }, + { + "locationName": "[parameters('secondaryRegion')]", + "failoverPriority": 1 + } + ] + }, + "resources": + [ + { + "type": "Microsoft.DocumentDB/databaseAccounts", + "name": "[variables('accountName')]", + "apiVersion": "2016-03-31", + "location": "[parameters('location')]", + "kind": "MongoDB", + "properties": { + "consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]", + "locations": "[variables('locations')]", + "databaseAccountOfferType": "Standard", + "enableMultipleWriteLocations": "[parameters('multipleWriteLocations')]" + } + }, + { + "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases", + "name": "[concat(variables('accountName'), '/mongodb/', parameters('databaseName'))]", + "apiVersion": "2016-03-31", + "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('accountName'))]" ], + "properties":{ + "resource":{ + "id": "[parameters('databaseName')]" + }, + "options": { "throughput": "[parameters('throughput')]" } + } + }, + { + "type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/collections", + "name": "[concat(variables('accountName'), '/mongodb/', parameters('databaseName'), '/', parameters('collection1Name'))]", + "apiVersion": "2016-03-31", + "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('accountName'), 'mongodb', parameters('databaseName'))]" ], + "properties": + { + "resource":{ + "id": "[parameters('collection1Name')]", + "shardKey": { "user_id": "Hash" }, + "indexes": [ + { + "key": { "keys":["user_id", "user_address"] }, + "options": { "unique": "true" } + }, + { + "key": { "keys":["_ts"] }, + "options": { "expireAfterSeconds": "2629746" } + } + ], + "options": { + "If-Match": "" + } + } + } + }, + { + "type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/collections", + "name": "[concat(variables('accountName'), '/mongodb/', parameters('databaseName'), '/', parameters('collection2Name'))]", + "apiVersion": "2016-03-31", + "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('accountName'), 'mongodb', parameters('databaseName'))]" ], + "properties": + { + "resource":{ + "id": "[parameters('collection2Name')]", + "shardKey": { "company_id": "Hash" }, + "indexes": [ + { + "key": { "keys":["company_id", "company_address"] }, + "options": { "unique": "true" } + }, + { + "key": { "keys":["_ts"] }, + "options": { "expireAfterSeconds": "2629746" } + } + ], + "options": { + "If-Match": "" + } + } + } + } + ] +} diff --git a/101-cosmosdb-mongodb/azuredeploy.parameters.json b/101-cosmosdb-mongodb/azuredeploy.parameters.json new file mode 100644 index 000000000000..e2d52c7c021b --- /dev/null +++ b/101-cosmosdb-mongodb/azuredeploy.parameters.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "accountName": { + "value": "GEN-UNIQUE" + }, + "primaryRegion": { + "value": "West US" + }, + "secondaryRegion": { + "value": "East US" + }, + "databaseName": { + "value": "myDatabase" + }, + "collection1Name": { + "value": "myCollection1" + }, + "collection2Name": { + "value": "myCollection2" + } + } +} diff --git a/101-cosmosdb-mongodb/metadata.json b/101-cosmosdb-mongodb/metadata.json new file mode 100644 index 000000000000..f7d5b454bcd3 --- /dev/null +++ b/101-cosmosdb-mongodb/metadata.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://aka.ms/azure-quickstart-templates-metadata-schema#", + "type": "QuickStart", + "itemDisplayName": "Create an Azure Cosmos DB account for MongoDB API", + "description": "This template creates an Azure Cosmos DB account for MongoDB API in two regions using shared throughput at database level with two collections.", + "summary": "This template creates an Azure Cosmos DB account for MongoDB API in two regions using shared throughput at database level with two collections.", + "githubUsername": "markjbrown", + "dateUpdated": "2019-04-25" +} \ No newline at end of file