|
| 1 | +--- |
| 2 | +title: Integrate MongoDB Atlas cluster with Service Connector |
| 3 | +description: Integrate MongoDB Atlas cluster into your application with Service Connector. |
| 4 | +author: qianwens |
| 5 | +ms.author: qianwens |
| 6 | +ms.service: service-connector |
| 7 | +ms.topic: how-to |
| 8 | +ms.custom: engagement-fy23 |
| 9 | +ms.date: 05/08/2025 |
| 10 | +--- |
| 11 | + |
| 12 | +# Integrate MongoDB Atlas cluster with Service Connector |
| 13 | + |
| 14 | +This page shows supported authentication methods and clients, and shows sample code you can use to connect MongoDB Atlas cluster from Azure compute services using Service Connector. You might still be able to connect to MongoDB Atlas cluster in other programming languages without using Service Connector. This page also shows default environment variable names and values you get when you create the service connection. |
| 15 | + |
| 16 | +## Supported compute services |
| 17 | + |
| 18 | +Service Connector can be used to connect the following compute services to MongoDB Atlas cluster: |
| 19 | + |
| 20 | +- Azure App Service |
| 21 | +- Azure Container Apps |
| 22 | +- Azure Functions |
| 23 | +- Azure Kubernetes Service (AKS) |
| 24 | + |
| 25 | +## Supported authentication types and client types |
| 26 | + |
| 27 | +The table below shows which combinations of authentication methods and clients are supported for connecting your compute service to MongoDB Atlas cluster using Service Connector. A “Yes” indicates that the combination is supported, while a “No” indicates that it is not supported. |
| 28 | + |
| 29 | +| Client type | System-assigned managed identity | User-assigned managed identity | Secret/connection string | Service principal | |
| 30 | +|---------------------------|:--------------------------------:|:------------------------------:|:------------------------:|:-----------------:| |
| 31 | +| .NET | No | No | Yes | No | |
| 32 | +| Go (pg) | No | No | Yes | No | |
| 33 | +| Java (JDBC) | No | No | Yes | No | |
| 34 | +| Java - Spring Boot (JDBC) | No | No | Yes | No | |
| 35 | +| Node.js (pg) | No | No | Yes | No | |
| 36 | +| PHP (native) | No | No | Yes | No | |
| 37 | +| Python (psycopg2) | No | No | Yes | No | |
| 38 | +| Python-Django | No | No | Yes | No | |
| 39 | +| Ruby (ruby-pg) | No | No | Yes | No | |
| 40 | +| None | No | No | Yes | No | |
| 41 | + |
| 42 | + |
| 43 | +## Default environment variable names or application properties and sample code |
| 44 | + |
| 45 | +Reference the connection details and sample code in the following tables, according to your connection's authentication type and client type, to connect compute services to MongoDB Atlas cluster. For more information about naming conventions, check the [Service Connector internals](concept-service-connector-internals.md#configuration-naming-convention) article. |
| 46 | + |
| 47 | +### Connection String |
| 48 | + |
| 49 | +> [!WARNING] |
| 50 | +> Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable. |
| 51 | +
|
| 52 | +#### [.NET](#tab/dotnet) |
| 53 | + |
| 54 | +| Default environment variable name | Description | Example value | |
| 55 | +| ------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | |
| 56 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | .NET MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 57 | + |
| 58 | +#### [Java](#tab/java) |
| 59 | + |
| 60 | +| Default environment variable name | Description | Example value | |
| 61 | +| ------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 62 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | JDBC MongoDB Atlas connection string | `jdbc:mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 63 | + |
| 64 | +#### [Python](#tab/python) |
| 65 | + |
| 66 | +| Default environment variable name | Description | Example value | |
| 67 | +| ------------------------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 68 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | Python MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 69 | + |
| 70 | +#### [Django](#tab/django) |
| 71 | + |
| 72 | +| Default environment variable name | Description | Example value | |
| 73 | +| ------------------------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 74 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | Django MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 75 | + |
| 76 | +#### [Go](#tab/go) |
| 77 | + |
| 78 | +| Default environment variable name | Description | Example value | |
| 79 | +|-------------------------------------|---------------------------------|---------------------------------------------------------------------------------------------------------------------------------| |
| 80 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | Go MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 81 | + |
| 82 | +#### [NodeJS](#tab/nodejs) |
| 83 | + |
| 84 | +| Default environment variable name | Description | Example value | |
| 85 | +|-------------------------------------|---------------------------------|---------------------------------------------------------------------------------------------------------------------------------| |
| 86 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | NodeJS MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 87 | + |
| 88 | +#### [PHP](#tab/php) |
| 89 | + |
| 90 | +| Default environment variable name | Description | Example value | |
| 91 | +|-----------------------------------|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------| |
| 92 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | PHP native MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 93 | + |
| 94 | +#### [Ruby](#tab/ruby) |
| 95 | + |
| 96 | +| Default environment variable name | Description | Example value | |
| 97 | +|-----------------------------------|---------------------------------|----------------------------------------------------------------------------------| |
| 98 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | Ruby MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 99 | + |
| 100 | +#### [Other](#tab/none) |
| 101 | + |
| 102 | +| Default environment variable name | Description | Example value | |
| 103 | +|-----------------------------------|---------------------------------|----------------------------------------------------------------------------------| |
| 104 | +| `MONGODBATLAS_CLUSTER_CONNECTIONSTRING` | MongoDB Atlas connection string | `mongodb+srv://myUser:[email protected]/?retryWrites=true&w=majority&appName=Cluster0` | |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +#### Sample code |
| 109 | + |
| 110 | +Refer to the steps and code below to connect to MongoDB Atlas cluster using a connection string. |
| 111 | +[!INCLUDE [code sample for mongodb secrets](./includes/code-mongodb-atlas-secret.md)] |
| 112 | + |
| 113 | + |
| 114 | +## Next steps |
| 115 | + |
| 116 | +Follow the tutorials listed below to learn more about Service Connector. |
| 117 | + |
| 118 | +> [!div class="nextstepaction"] |
| 119 | +> [Learn about Service Connector concepts](./concept-service-connector-internals.md) |
0 commit comments