Skip to content

Commit c230fe6

Browse files
authored
Merge pull request #126210 from michael-duffey-veloquix/patch-1
Corrections for Service Connector -> MongoDB C# example
2 parents 9ee4c97 + 98c6cdb commit c230fe6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

articles/service-connector/includes/code-cosmosmongo-me-id.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ ms.author: wchi
2727
using MongoDB.Driver;
2828
using Azure.Identity;
2929
using System.Text.Json;
30-
31-
var endpoint = Environment.GetEnvironmentVariable("AZURE_COSMOS_RESOURCEENDPOINT");
30+
31+
// you can retrieve the endpoint of the resource with the following env variable:
32+
// Environment.GetEnvironmentVariable("AZURE_COSMOS_RESOURCEENDPOINT");
3233
var listConnectionStringUrl = Environment.GetEnvironmentVariable("AZURE_COSMOS_LISTCONNECTIONSTRINGURL");
3334
var scope = Environment.GetEnvironmentVariable("AZURE_COSMOS_SCOPE");
3435
@@ -40,7 +41,7 @@ ms.author: wchi
4041
// var tokenProvider = new DefaultAzureCredential(
4142
// new DefaultAzureCredentialOptions
4243
// {
43-
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_COSMOS_CLIENTID");
44+
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_COSMOS_CLIENTID")
4445
// }
4546
// );
4647
@@ -57,10 +58,10 @@ ms.author: wchi
5758
// Get the connection string.
5859
var httpClient = new HttpClient();
5960
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken.Token}");
60-
var response = await httpClient.POSTAsync(listConnectionStringUrl);
61+
var response = await httpClient.PostAsync(new Uri(listConnectionStringUrl), null);
6162
var responseBody = await response.Content.ReadAsStringAsync();
6263
var connectionStrings = JsonSerializer.Deserialize<Dictionary<string, List<Dictionary<string, string>>>>(responseBody);
63-
string connectionString = connectionStrings["connectionStrings"][0]["connectionString"];
64+
var connectionString = connectionStrings["connectionStrings"][0]["connectionString"];
6465
6566
// Connect to Azure Cosmos DB for MongoDB
6667
var client = new MongoClient(connectionString);
@@ -306,4 +307,4 @@ The authentication type is not supported for Spring Boot.
306307
307308
308309
### [Other](#tab/none)
309-
For other languages, you can use the MongoDB resource endpoint and other properties that Service Connector sets to the environment variables to connect to Azure Cosmos DB for MongoDB. For environment variable details, see [Integrate Azure Cosmos DB for MongoDB with Service Connector](../how-to-integrate-cosmos-db.md).
310+
For other languages, you can use the MongoDB resource endpoint and other properties that Service Connector sets to the environment variables to connect to Azure Cosmos DB for MongoDB. For environment variable details, see [Integrate Azure Cosmos DB for MongoDB with Service Connector](../how-to-integrate-cosmos-db.md).

0 commit comments

Comments
 (0)