[CSHARP-2887] MongoClientSettings class not birectional with managing connection URL Created: 21/Dec/19  Updated: 27/Oct/23  Resolved: 23/Dec/19

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.10.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Hari Lubovac Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-3953 Simplify and consolidate connection s... Backlog

 Description   

Assuming that `MongoClientSettings.ToString` method does what the below example implies, I would expect it to work. It shows how a valid connection string - after it's been parsed,  default values derived from it, and finally reconstructed -  no longer works.

[Fact]
public void MongoClientSettings_Reconstruction_Localhost()
{
string connectionString = "mongodb://localhost:27017";
var settings = MongoDB.Driver.MongoClientSettings.FromConnectionString(connectionString);
 
string generatedConnectionString = settings.ToString();
 
// Fails here with "The connection string is not valid" error
// (MongoDB.Driver.MongoConfigurationException)
var settings2 = MongoDB.Driver.MongoClientSettings.FromConnectionString(generatedConnectionString);
 
Assert.True(settings.Equals(settings2));
}



 Comments   
Comment by Dmitry Lukyanov (Inactive) [ 23/Dec/19 ]

MongoClientSettings.ToString() is not designed to return connection string. One from the reason for it, that MongoClientSettings can contain options that are not presented in the connection string. You can reach the target of your test with MongoUrl.

Generated at Wed Feb 07 21:43:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.