[GODRIVER-428] Format ConnString struct back to string Created: 24/May/18  Updated: 29/Nov/22  Resolved: 08/Oct/18

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Kamil Dziedzic Assignee: Kristofer Brandow (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-2226 Build a Connection String programmati... Closed

 Description   

Hi, would it be a big deal for you to create func to format ConnString struct back to string?

https://github.com/mongodb/mongo-go-driver/blob/master/core/connstring/connstring.go#L94

Currently above returns original string but I would like to modify ConnString and then format it back to string/DSN. Something like in MySQL driver https://github.com/go-sql-driver/mysql/blob/master/dsn.go#L111



 Comments   
Comment by Kristofer Brandow (Inactive) [ 08/Oct/18 ]

Hi arvenil,

Since no other drivers support this, we are not going to support this at this time.

--Kris

Comment by Kamil Dziedzic [ 24/May/18 ]

DSN for cluster is defined as a) list of servers b) mongodb+srv. In both cases we get a list of hosts in one DSN, but I would like to create one DSN per host. So from what user gives me from MongoDB Atlas e.g.

mongo "mongodb+srv://cluster0-gc2qe.mongodb.net/test" --username admin

mongo "mongodb://cluster0-shard-00-00-gc2qe.mongodb.net:27017,cluster0-shard-00-01-gc2qe.mongodb.net:27017,cluster0-shard-00-02-gc2qe.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --ssl --authenticationDatabase admin --username admin --password <PASSWORD>

I want to rewrite back to:

mongo "mongodb://cluster0-shard-00-00-gc2qe.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --ssl --authenticationDatabase admin --username admin --password <PASSWORD>
mongo "mongodb://cluster0-shard-00-01-gc2qe.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --ssl --authenticationDatabase admin --username admin --password <PASSWORD>
mongo "mongodb://cluster0-shard-00-02-gc2qe.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --ssl --authenticationDatabase admin --username admin --password <PASSWORD>

With Format() on ConnString struct I should be able to just modify the list of ConnString.Hosts and call Format()

Generated at Thu Feb 08 08:34:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.