doucuodan0897 2019-07-27 18:56
浏览 116
已采纳

官方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.

  • 写回答

1条回答 默认 最新

  • doucu7525 2019-08-07 22:29
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog