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

官方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 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题
  • ¥15 Selenium+docker Chrome不能运行
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到