go版本:go1.11.2
连接字符串: mongodb+srv://<username>:<pw>@<host>/test?replicaSet=<replicaSetName>&retryWrites=true&w=majority
MongoDB Atlas:网络访问当前设置为 0.0.0.0/0
MongoDB Atlas: Sandbox M0 MongoDB version 4.0.10
Heroku MongoDB 插件: 沙箱
我正在尝试使用上述连接字符串从 heroku 应用程序连接到 MongoDB Atlas 集群。这在本地工作正常,所以我知道连接字符串是有效的。 但是,每当应用程序(golang 应用程序)在 heroku 端启动时,我都会收到以下错误。
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
错误似乎与 TLS 证书相关。我正在使用 Official MongoDB Go Driver
如果这与 TLS 相关,为什么我在本地没有收到此错误? 我发现这个问题似乎和我的一样,但我不知道该怎么做.... Related Issue
有没有其他人遇到过使用 Golang 从 Heroku 连接到 MongoDB Atlas 的类似问题?
如果您需要更多信息,请告诉我。我很茫然。我尝试了各种连接字符串组合,但似乎没有任何效果。
最佳答案
这与问题 crypto/x509: root_cgo_darwin and root_nocgo_darwin omit some system certs 有关.钥匙串(keychain)中的某些 CA 证书被省略的问题。
此修复已在 Go v1.12 中发布,并且还向后移植到 Go v1.11.6。
关于mongodb - 官方 mongodb go-driver heroku 连接到 mongodb atlas 沙箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57235190/