Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
APPLIES TO:
MongoDB vCore
In this quickstart, you create a new Azure Cosmos DB for MongoDB vCore cluster. This cluster contains all of your MongoDB resources: databases, collections, and documents. The cluster provides a unique endpoint for various tools and SDKs to connect to Azure Cosmos DB and perform everyday operations.
The Bicep file used in this quickstart is from Azure Quickstart Templates.
@description('Azure Cosmos DB MongoDB vCore cluster name')
@maxLength(44)
param clusterName string = 'msdocs-${uniqueString(resourceGroup().id)}'
@description('Location for the cluster.')
param location string = resourceGroup().location
@description('Username for admin user')
param adminUsername string
@secure()
@description('Password for admin user')
@minLength(8)
@maxLength(128)
param adminPassword string
resource cluster 'Microsoft.DocumentDB/mongoClusters@2022-10-15-preview' = {
name: clusterName
location: location
properties: {
administratorLogin: adminUsername
administratorLoginPassword: adminPassword
nodeGroupSpecs: [
{
kind: 'Shard'
shardCount: 1
sku: 'M40'
diskSizeGB: 128
enableHa: false
}
]
}
}
resource firewallRules 'Microsoft.DocumentDB/mongoClusters/firewallRules@2022-10-15-preview' = {
parent: cluster
name: 'AllowAllAzureServices'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
Note
Kindly note that in the above code, shardGroupSpecs is called nodeGroupSpecs.
Two Azure resources are defined in the Bicep file:
Microsoft.DocumentDB/mongoclusters
: Creates an Azure Cosmos DB for MongoDB vCore cluster.
Microsoft.DocumentDB/mongoClusters/firewallRules
: Creates firewall rules for the Azure Cosmos DB for MongoDB vCore cluster.Create an Azure Cosmos DB for MongoDB vCore cluster by using the Bicep template.
Create shell variables for resourceGroupName, and location
# Variable for resource group name and location
resourceGroupName="msdocs-cosmos-quickstart-rg"
location="eastus"
If you haven't already, sign in to the Azure CLI using the az login
command.
Use the az group create
command to create a new resource group in your subscription.
az group create \
--name $resourceGroupName \
--location $location
Use az deployment group create
to deploy the bicep template. You're then prompted to enter a value for the adminUsername
and adminPassword
parameters.
az deployment group create \
--resource-group $resourceGroupName \
--template-file 'main.bicep'
Tip
Alternatively, use the --parameters
option to pass in a parameters file with pre-defined values.
az deployment group create \
--resource-group $resourceGroupName \
--template-file 'main.bicep' \
--parameters @main.parameters.json
This example JSON file injects clusteradmin
and P@ssw.rd
values for the adminUsername
and adminPassword
parameters respectively.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": "clusteradmin"
},
"adminPassword": {
"value": "P@ssw.rd"
}
}
}
Wait for the deployment operation to complete before moving on.
List the resources deployed by the Bicep template to your target resource group.
Use az resource list
to get a list of resources in your resource group.
az resource list \
--resource-group $resourceGroupName \
--location $location \
--output tsv
In the example output, look for resources that have a type of Microsoft.DocumentDB/mongoClusters
. Here's an example of the type of output to expect:
Name ResourceGroup Location Type Status
-------------------- --------------------------- ---------- ---------------------------------- --------
msdocs-sz2dac3xtwzzu msdocs-cosmos-quickstart-rg eastus Microsoft.DocumentDB/mongoClusters
When you're done with your Azure Cosmos DB for MongoDB vCore cluster, you can delete the Azure resources you created so you don't incur more charges.
Use az group delete
to remove the resource group from your subscription.
az group delete \
--name $resourceGroupName
In this guide, you learned how to create an Azure Cosmos DB for MongoDB vCore cluster. You can now migrate data to your cluster.
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Implement vCore-based Azure Cosmos DB for MongoDB - Training
Implement vCore-based Azure Cosmos DB for MongoDB.
Certification
Microsoft Certified: Azure Cosmos DB Developer Specialty - Certifications
Write efficient queries, create indexing policies, manage, and provision resources in the SQL API and SDK with Microsoft Azure Cosmos DB.
Documentation
Azure Cosmos DB for MongoDB (vCore) documentation
Azure Cosmos DB for MongoDB in vCore architecture makes it easy to create a database with full native MongoDB support.
Compatibility and feature support v1 - Azure Cosmos DB for MongoDB vCore
Review Azure Cosmos DB for MongoDB vCore supported features and syntax including; commands, query support, datatypes, aggregation, operators and indexes.
Azure Cosmos DB for MongoDB vCore is your multi-cloud solution
Azure Cosmos DB for MongoDB vCore offers a flexible, multi-cloud database service, using the MongoDB wire protocol for seamless migration and integration across environments.