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.

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

报告相同问题?

悬赏问题

  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?