官方mongodb go-driver heroku与mongodb atlas沙箱的连接

go version: go1.11.2

connnection string: mongodb+srv://<username>:<pw>@<host>/test?replicaSet=<replicaSetName>&retryWrites=true&w=majority

MongoDB Atlas: Network access is currently set to 0.0.0.0/0

MongoDB Atlas: Sandbox M0 MongoDB version 4.0.10

Heroku MongoDB addon: Sandbox

I am attempting to connect from a heroku app to a MongoDB Atlas cluster with the above connection string. This works fine locally so I know the connection string is valid. However, whenever the app (golang app) starts up on heroku side I am getting the following errors.

2019/07/27 16:18:49 server selection error: server selection timeout
current topology: Type: ReplicaSetNoPrimary
Servers:
Addr: rapi0-shard-00-02- 
yqd60.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 
0, Last error: connection() : x509: certificate signed by unknown 
authority
Addr: rapi0-shard-00-00- 
yqd60.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 
0, Last error: connection() : x509: certificate signed by unknown 
authority
Addr: rapi0-shard-00-01- 
yqd60.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 
0, Last error: connection() : x509: certificate signed by unknown 
authority

The errors seem to be TLS certificate related. I am using the Official MongoDB Go Driver

If this is TLS related why am I not getting this error locally? I found this issue which seems to be the same as mine, but I am not sure what to make of it .... Related Issue

Has anyone else had similar issues with connecting to MongoDB Atlas from Heroku using Golang?

Please let me know if you need any more info. I am at a loss. I have tried various combinations of connection strings and nothing seems to work.

This is related to issue crypto/x509: root_cgo_darwin and root_nocgo_darwin omit some system certs. The issue where some CA certs in keychains are omitted.

The fix was released in Go v1.12, and also back-ported to Go v1.11.6.