Integrate Azure Cosmos DB for MongoDB with Service Connector
This page shows the supported authentication types and client types for the Azure Cosmos DB for MongoDB using Service Connector. You might still be able to connect to the Azure Cosmos DB for MongoDB in other programming languages without using Service Connector. This page also shows default environment variable names and values (or Spring Boot configuration) you get when you create the service connection. You can learn more about Service Connector environment variable naming convention.
Supported compute services
- Azure App Service
- Azure Container Apps
- Azure Spring Apps
Supported authentication types and client types
Supported authentication and clients for App Service, Container Apps, and Azure Spring Apps:
Client type | System-assigned managed identity | User-assigned managed identity | Secret / connection string | Service principal |
---|---|---|---|---|
.NET | ![]() |
![]() |
![]() |
![]() |
Java | ![]() |
![]() |
![]() |
![]() |
Java - Spring Boot | ![]() |
|||
Node.js | ![]() |
![]() |
![]() |
![]() |
Go | ![]() |
![]() |
![]() |
![]() |
Default environment variable names or application properties
Use the connection details below to connect compute services to Azure Cosmos DB. For each example below, replace the placeholder texts <mongo-db-admin-user>
, <password>
, <Azure-Cosmos-DB-API-for-MongoDB-account>
, <subscription-ID>
, <resource-group-name>
, <client-secret>
, and <tenant-id>
with your own information.
Azure App Service and Azure Container Apps
Secret / Connection string
Default environment variable name | Description | Example value |
---|---|---|
AZURE_COSMOS_CONNECTIONSTRING | MongoDB API connection string | mongodb://<mongo-db-admin-user>:<password>@<mongo-db-server>.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@<mongo-db-server>@ |
System-assigned managed identity
Default environment variable name | Description | Example value |
---|---|---|
AZURE_COSMOS_LISTCONNECTIONSTRINGURL | The URL to get the connection string | https://management.azure.com/subscriptions/<subscription-ID>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<Azure-Cosmos-DB-API-for-MongoDB-account>/listConnectionStrings?api-version=2021-04-15 |
AZURE_COSMOS_SCOPE | Your managed identity scope | https://management.azure.com/.default |
AZURE_COSMOS_RESOURCEENDPOINT | Your resource endpoint | https://<Azure-Cosmos-DB-API-for-MongoDB-account>.documents.azure.com:443/ |
User-assigned managed identity
Default environment variable name | Description | Example value |
---|---|---|
AZURE_COSMOS_LISTCONNECTIONSTRINGURL | The URL to get the connection string | https://management.azure.com/subscriptions/<subscription-ID>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<Azure-Cosmos-DB-API-for-MongoDB-account>/listConnectionStrings?api-version=2021-04-15 |
AZURE_COSMOS_SCOPE | Your managed identity scope | https://management.azure.com/.default |
AZURE_COSMOS_CLIENTID | Your client ID | <client-ID> |
AZURE_COSMOS_RESOURCEENDPOINT | Your resource endpoint | https://<Azure-Cosmos-DB-API-for-MongoDB-account>.documents.azure.com:443/ |
Service principal
Default environment variable name | Description | Example value |
---|---|---|
AZURE_COSMOS_LISTCONNECTIONSTRINGURL | The URL to get the connection string | https://management.azure.com/subscriptions/<subscription-ID>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<Azure-Cosmos-DB-API-for-MongoDB-account>/listConnectionStrings?api-version=2021-04-15 |
AZURE_COSMOS_SCOPE | Your managed identity scope | https://management.azure.com/.default |
AZURE_COSMOS_CLIENTID | Your client ID | <client-ID> |
AZURE_COSMOS_CLIENTSECRET | Your client secret | <client-secret> |
AZURE_COSMOS_TENANTID | Your tenant ID | <tenant-ID> |
AZURE_COSMOS_RESOURCEENDPOINT | Your resource endpoint | https://<Azure-Cosmos-DB-API-for-MongoDB-account>.documents.azure.com:443/ |
Azure Spring Apps
Default environment variable name | Description | Example value |
---|---|---|
spring.data.mongodb.database | Your database | <database-name> |
spring.data.mongodb.uri | Your database URI | mongodb://<mongo-db-admin-user>:<password>@<mongo-db-server>.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@<mongo-db-server>@ |
Next steps
Follow the tutorials listed below to learn more about Service Connector.
Feedback
Submit and view feedback for