要解决这个问题:我是否需要在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安全连接?
我在 Atlas MongoDB Cloud 集群上托管了一个 mongodb 数据库。我目前正在使用 mongoose 访问我的 node.js 应用程序中的数据库:
mongoose.connect("mongodb://user:pw@cluster0-shard-00-00-***.mongodb.net:***,cluster0-shard-00-01-***.mongodb.net:***,cluster0-shard-00-02-***.mongodb.net:***/admin?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin");
Run Code Online (Sandbox Code Playgroud)
因为 Atlas MongoDB Cloud 有一个白名单,而 Heroku 不提供为我的应用程序获取固定 IP 地址的可能性,所以我使用Fixie 附加组件。基本上,Fixie 充当出站流量的代理。
这样,我可以通过 HTTP 请求资源,这些资源通过 Fixie 提供的固定 IP 地址进行隧道传输。但我需要的是使用 Fixie 的代理连接到 Atlas Cloud 集群,以便从数据库中检索和修改数据。
可以用猫鼬来完成吗?
该mongoose.connect函数接受一个选项参数,但我找不到关于通过代理建立连接的任何选项。