[GODRIVER-879] Not able to connect to MongoDB Atlas without starting local Mongo server Created: 15/Mar/19  Updated: 03/Apr/19  Resolved: 02/Apr/19

Status: Closed
Project: Go Driver
Component/s: Connections
Affects Version/s: 1.0.0-rc1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Yong Wei Lun Assignee: Kristofer Brandow (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 18.04.2 LTS,
Go version go1.12 linux/amd64


Issue Links:
Duplicate
duplicates GODRIVER-829 Go 1.11 LookupSRV cannot unmarshal DN... Closed

 Description   

I connect to MongoDB Atlas with the following code segment

client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://admin:admin@cluster0-7odzu.mongodb.net/test"))

I was not able to connect to the cluster, hitting this error

 

2019/03/15 15:02:29 server selection error: server selection timeout current topology: Type: Unknown Servers: Addr: localhost:27017, Type: Unknown, State: Connected, Avergage RTT: 0, Last error: dial tcp 127.0.0.1:27017: connect: connection refused exit status 1

However, when I start my local Mongod service, it can connect, everything works fiine



 Comments   
Comment by Yong Wei Lun [ 03/Apr/19 ]

Hi Kris, 

But I wasn't running on containers or VMs, it should not have DNS errors

Comment by Kristofer Brandow (Inactive) [ 02/Apr/19 ]

Hi weilun_95@hotmail.com, this is actually a duplicate of GODRIVER-829. The reason we don't see an error is because of GODRIVER-908, which was suppressing the DNS error. Please refer to that ticket for a fix to this problem.

--Kris

Comment by Yong Wei Lun [ 02/Apr/19 ]

Hi Kris, the full working example as below

client, err := mongo.NewClient(options.Client().ApplyURI(dbUri))
log.Println("client created")
if err != nil {
 log.Fatal(err)
}
 
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
err = client.Connect(ctx)
 
if err != nil {
 log.Fatal(err)
}
log.Println("client connected")
 
err = client.Ping(ctx, readpref.Primary())
if err != nil {
 log.Fatal(err)
}
log.Println("client ping")

When I run on Ubuntu environment, it stops at 'client connected', and timeout after half minute, depending on the context. When I start local Mongod service, it will successfully ping the database, but it will make a connection to local MongoDB instead of Atlas. 

 

The same code snippet I run it on Mac environment, it works as expected, able to connect to Atlas.

Comment by Kristofer Brandow (Inactive) [ 01/Apr/19 ]

Hi weilun_95@hotmail.com, can you please provide an fully working code example that replicates the issue?

Comment by Yong Wei Lun [ 16/Mar/19 ]

I was able to connect to MongoDB Atlas without starting local Mongod service from macOS 10.14.2, Go 1.12.1 darwin/amd64, Driver 1.0.0 without issues. 

I have tried to reinstall Go on my Ubuntu 18.04.2 LTS, the problem still exist. 

I guess the problem is with the Linux build? 

Comment by Yong Wei Lun [ 15/Mar/19 ]

I updated the driver to v1.0.0 and I am using Go 1.12, the problem still persist. 

I found out that it actually connect to my local MongoDB instead of Atlas when I start my local mongod service

Comment by Kristofer Brandow (Inactive) [ 15/Mar/19 ]

I'm using Go 1.12 and v1.0.0 of the driver.

Comment by Yong Wei Lun [ 15/Mar/19 ]

Which Go version and Driver you were using?

Comment by Kristofer Brandow (Inactive) [ 15/Mar/19 ]

Hi weilun_95@hotmail.com,

I've tried connecting with the provided example and I was able to ping the server without a problem. Can you provide a fully working example?

--Kris

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