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.

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

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格