MongoDB database

Learn how to use a Mongo database in your application


The resource represents a Mongo database.

Resource format

resource db 'Applications.Datastores/mongoDatabases@2023-10-01-preview' = {
  name: 'db'
  properties: {
    environment: environment
    recipe: {
      // Name a specific Recipe to use
      name: 'azure-cosmosdb'
      // Set optional/required parameters (specific to the Recipe)
      parameters: {
        size: 'large'

resource db 'Applications.Datastores/mongoDatabases@2023-10-01-preview' = {
  name: 'db'
  properties: {
    environment: environment
    resourceProvisioning: 'manual'
    host: substring(, 0, lastIndexOf(, ':'))
    port: int(split(substring(,lastIndexOf(, ':') + 1), '/')[0])
    username: ''
    resources: [
      { id: }
    secrets: {
      connectionString: cosmosAccount.listConnectionStrings().connectionStrings[0].connectionString
      password: base64ToString(cosmosAccount.listKeys().primaryMasterKey)


Key Required Description Example
name y The name of your resource. mongo
location y The location of your resource. See common values for more information. global
properties y Properties of the resource. See below


Property Required Description Example(s)
application n The ID of the application resource this resource belongs to.
environment y The ID of the environment resource this resource belongs to.
resourceProvisioning n Specifies how the underlying service/resource is provisioned and managed. Options are to provision automatically via ‘recipe’ or provision manually via ‘manual’. Selection determines which set of fields to additionally require. Defaults to ‘recipe’. manual
recipe n Configuration for the Recipe which will deploy the backing infrastructure. See below
resources n An array of resources which underlay this resource. For example, an Azure CosmosDB database ID if the MongoDB resource is leveraging CosmosDB. See below
database n Database name of the target MongoDB mongodb-prod
host n The MongoDB host name.
port n The MongoDB port. 4242
username n The username for the MongoDB. 'myusername'
secrets n Secrets used when building the resource from values. See below


Property Required Description Example(s)
name n Specifies the name of the Recipe that should be deployed. If not set, the name defaults to default. name: 'azure-prod'
parameters n An object that contains a list of parameters to set on the Recipe. { size: 'large' }


Property Required Description Example(s)
id n Resource ID of the supporting resource.


Property Required Description Example(s)
connectionString n The connection string for the MongoDb. Write only. mongodb://
password n The password for the MongoDB. Write only. mypassword


The following methods are available on the Mongo database resource:

Method Description
connectionString() Get the connection string for the MongoDb.
username() Get the username for the MongoDB.
password() Get the password for the MongoDB.

Resource provisioning

Provision with a Recipe

Recipes automate infrastructure provisioning using approved templates. You can specify a Recipe name that is registered in the environment or omit the name and use the “default” Recipe.

Parameters can also optionally be specified for the Recipe.

Provision manually

If you want to manually manage your infrastructure provisioning outside of Recipes, you can set resourceProvisioning to 'manual' and provide all necessary parameters and values in order for Radius to be able to deploy/connect to the desired infrastructure.

Environment variables for connections

Other Radius resources, such as containers, may connect to a MongoDB resource via connections. When a connection to MongoDB named, for example, myconnection is declared, Radius injects values into environment variables that are then used to access the connected MongoDB resource:

Environment variable Example(s)