要解决这个问题:我是否需要在Heroku 上获得SSL支持,以便使用SSL 在Heroku和Atlas MongoDB Cloud之间建立连接?(TSL/SSL连接是访问Atlas MongoDB Cloud服务的必要条件).
我正在尝试将以node.js编写的Heroku应用程序连接到Atlas MongoDB Cloud托管的集群.
我当前的数据库托管在mLab(作为Heroku Add-on),用于通过mongoose访问集群的MongoDB URI是(使用xxx省略机密信息):
MONGODB_URI="mongodb://xxx:xxx@xxx-a0.mlab.com:23266,xxx-a1.mlab.com:xxx/xxx?replicaSet=rs-xxx"
Run Code Online (Sandbox Code Playgroud)
现在我已将我的数据从mLab迁移到Atlas MongoDB Cloud,我目前正在使用URI访问集群:
MONGODB_URI="mongodb://xxx:xxx@cluster0-shard-xxx.mongodb.net:xxx,cluster0-shard-xxx.mongodb.net:xxx,cluster0-shard-xxx.mongodb.net:xxx/xxx?replicaSet=xxx&ssl=true&authSource=admin"
Run Code Online (Sandbox Code Playgroud)
在我的机器本地运行我的Heroku应用程序时,我可以毫无问题地访问数据库.我也可以使用mongo shell连接到集群.
但是,在Heroku中运行App时,无法建立连接.在Browser JS控制台中,我收到503服务不可用消息.在heroku中,我收到错误:
no primary found in replica set
Run Code Online (Sandbox Code Playgroud)
我知道Atlas MongoDB Cloud需要SSL连接,与mLab不同.在我的本地计算机中,我认为正在使用自签名证书成功连接到群集.
我的问题是:我是否需要在Heroku中获得SSL支持才能访问在Heroku和MongoDB Atlas之间建立安全连接?或者Heroku中的SSL支持只需要客户端/ Heroku安全连接?