[CSHARP-1726] It is not possible to set Server attribute in MongoClientSettings. it remains 'localhost'. Created: 26/Jul/16  Updated: 07/Feb/17  Resolved: 07/Feb/17

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

Type: Bug Priority: Minor - P4
Reporter: Jan Sturm Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

windows7



 Description   

this code does not work:(the Server attribute remains: localhost)

MongoClientSettings setting = new MongoClientSettings();
setting.Server = new MongoServerAddress($"mongodb://{_mongoDbHost}");

i have to clone the current Settings
MongoClientSettings setting = _dataBaseClient.Settings.Clone();
setting.Credentials = new[]

{ MongoCredential.CreateCredential(dataBase, userName, _password2Secure[password]) }

;
_dataBaseClient = new MongoClient(setting);



 Comments   
Comment by Jan Sturm [ 26/Jul/16 ]

the code snipped was from stackoverflow.
however you were right, when i do not pass mongodb:// but the name of server directly it works.

shouldn't it throw an exception then ?

but yes you can close the issue
sorry.

Comment by Jan Sturm [ 26/Jul/16 ]

i took this code snippet from the internet (codeproject or something), will retry it with dns name only

Comment by Robert Stam [ 26/Jul/16 ]

I am unable to reproduce this. When I change the value of the Server property of MongoClientSettings it actually does get a new value.

FYI, the host parameter to the MongoServerAddress constructor must be a DNS host name, not a MongoDB URL.

Keep in mind that once you pass the MongoClientSettings to a MongoClient constructor its values are frozen. So you can only change the Server value (or any other value) before you create the MongoClient instance.

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