[GODRIVER-1453] mongo.NewClient does not return any error when providing invalid Mongo URI Created: 27/Dec/19  Updated: 07/Jan/20  Resolved: 07/Jan/20

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

Type: Bug Priority: Major - P3
Reporter: cyan 3d Assignee: Divjot Arora (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello,

 

 

const (
     MONGO_URL = "mongodb://ASASASAS"
)
 
func main() {
     client, err := mongo.NewClient(options.Client().ApplyURI(MONGO_URL))
     if err != nil {
         log.Fatal(err)
     }
}

This code should return error, as I'm providing an invalid URI. But it is not returning any error, which is confusing.

 



 Comments   
Comment by Divjot Arora (Inactive) [ 07/Jan/20 ]

Hi cyantarek.cg@gmail.com,

The URI in the example is not invalid. The driver treats "ASASASAS" as a hostname and attempts to connect to it. If you construct a client using a non-existent hostname, any operations done with that client will return a server selection error once the server selection timeout expires (30 seconds by default).

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