[GODRIVER-1204] Cannot connect to MongoDB Atlas M0 sandbox Created: 24/Jul/19  Updated: 27/Oct/23  Resolved: 05/Aug/19

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

Type: Bug Priority: Major - P3
Reporter: Junbai Hou Assignee: Emmanuel Eppinger (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Atlas:M0 Sandbox, ver 4.0.10
OS: Ubuntu 18.04 on AWS EC2
Golang: 1.12.7
DNS server:8.8.8.8


Attachments: PNG File image-2019-07-24-00-49-30-796.png    

 Description   

The code snippet below didn't work

ClientOpt := options.Client().ApplyURI("some address")
Client,err := mongo.Connect(context.TODO(),ClientOpt)
if err!=nil {
    panic(err)
}
collection:=Client.Database("something").Collection("another")
Obj1 := SomeObj{}
res,error:=collection.InsertOne(context.TODO(),Obj1)
if error!=nil {
    panic(error)
}



 Comments   
Comment by Emmanuel Eppinger (Inactive) [ 05/Aug/19 ]

No problem. Glad you figured it out!!!

Comment by Junbai Hou [ 05/Aug/19 ]

Hi Emmanuel,

 

Thank you so much for the suggestion! I just realized that I didn't add the ip address of my ec2 instance to the atlas ip whitelist. It works now! Sorry for this misleading bug report. 

 

Best,

Junbai

 

  

Comment by Emmanuel Eppinger (Inactive) [ 05/Aug/19 ]

Hey Junbai,

 

I think this might be either an issue with atlas or maybe the ec2 instance itself. Would you be able to reproduce the issue on another driver?

 

Heres some example python3 [pymongo|https://api.mongodb.com/python/current/] to try. If it works then that would suggest that this is indeed a bug with the go driver, if not then it might suggest that the issue is with your ec2 instance or atlas.

 

from pymongo import MongoClient 
try: 
    client = MongoClient('your uri here...?retryWrites=true&w=majority') 
    coll = client.db_name.coll_name 
    print("everything worked!!!\nres:", coll.insert_one({"x" : 1}))
except Exception as e: 
    print("something wrong happened:", e)

Also you should try to ping with netcat with TCP the ip address + port of your atlas cluster from your ec2 instance to see if that fails. If it fails that would suggest that there is some type of permissioning issue with your ec2 instance.

 

Thanks and let us know what happens

Emmanuel

 

 

 

 

 

 

Comment by Junbai Hou [ 02/Aug/19 ]

It still doesn't work on the ec2 instance after I changed the code accordingly.

The initial client.connect() succeeds, but any following client.Ping() or readwrite operations would result in the error.

Comment by Emmanuel Eppinger (Inactive) [ 02/Aug/19 ]

Hi Junbai,

 

I tried it even with your uri and it worked totally fine for me. Do you still get the issue if you remove the 

?retryWrites=true&w=majority from the uri and add .SetRetryWrites(true).SetWriteConcern(writeconcern.New(writeconcern.WMajority())) to the client options.

 

Thanks

Emmanuel

Comment by Junbai Hou [ 01/Aug/19 ]

Hi Emmanuel,

The uri is

mongodb+srv://<user>:<password>@cluster0-gg3iq.mongodb.net/test?retryWrites=true&w=majority

Thank you,

Junbai

Comment by Emmanuel Eppinger (Inactive) [ 01/Aug/19 ]

Hi Junbai,

 

Would you be able to give us a reproduction connecting without your login credentials?

 

Thanks,

Emmanuel

Comment by Junbai Hou [ 25/Jul/19 ]

It turned out that the code works on my windows environment, but not on the ec2 instance.

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