在代理后面使用 mongoose 连接到 MongoDB 数据库 [英] Connect to MongoDB database using mongoose behind a proxy

查看:24
本文介绍了在代理后面使用 mongoose 连接到 MongoDB 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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

  1. 使用代理客户端(例如

    1. 使用您的 URI 端口作为目标端口为 mlab 创建规则,该规则使用您在上面创建的 HTTPS 代理作为其操作.

    1. 在规则列表中优先考虑您的 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 terminal

    failed 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

    1. Use a proxy client (e.g. Proxifier).
    2. Create a HTTPS proxy through port 8080 using your corporate proxy as the address.

    1. 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.

    1. Prioritize your mlab rule high in the rules list.

    这篇关于在代理后面使用 mongoose 连接到 MongoDB 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆