在代理后面使用 mongoose 连接到 MongoDB 数据库 [英] Connect to MongoDB database using mongoose behind a proxy
问题描述
我在 server.js 文件中使用 mongoose 连接到我在 mongolab 中的数据库:
mongoose.connect('mongodb://MyUsername:MyPassword@ds089702.mongolab.com:89702/todo');
当我使用 node server.js
命令启动我的服务器时,我在终端中看到这个错误
无法连接到 [ds089702.mongolab.com:89702]
我很确定这只是公司代理问题,所以我想知道如何使用 mongoose 通过公司代理连接到我的数据库?
谢谢!
我遇到了同样的问题,并找到了适合我的解决方案.
示例 mongodb URI:
mongodb://:@ds123456.mlab.com:37409/dbName
- 使用代理客户端(例如
- 使用您的 URI 端口作为目标端口为 mlab 创建规则,该规则使用您在上面创建的 HTTPS 代理作为其操作.
- 在规则列表中优先考虑您的 mlab 规则.
I am using mongoose to connect to my database in mongolab in my server.js file :
mongoose.connect('mongodb://MyUsername:MyPassword@ds089702.mongolab.com:89702/todo');
When i launch my server with
node server.js
command, i see this error in my terminalfailed to connect to [ds089702.mongolab.com:89702]
I am very sure that is just a corporate proxy problem, so I'm wondering how can I connect to my database over the corporate proxy using mongoose ?
Thank you!
解决方案I had the same problem and figured out a solution that worked for me.
Example mongodb URI:
mongodb://:@ds123456.mlab.com:37409/dbName
- Use a proxy client (e.g. Proxifier).
- Create a HTTPS proxy through port 8080 using your corporate proxy as the address.
- Create a rule for mlab using your URI's port as the target port, which uses the HTTPS proxy you created above as its action.
- Prioritize your mlab rule high in the rules list.
这篇关于在代理后面使用 mongoose 连接到 MongoDB 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!