【问题标题】:"Request timeout" H12 Heroku error tying to access MongoDB Atlas“请求超时”H12 Heroku 错误绑定访问 MongoDB Atlas
【发布时间】:2020-07-09 18:34:07
【问题描述】:

这个问题似乎很常见,但我已经尝试了几件事,但我仍然得到这个错误。

好的,所以我正在尝试使用我在 MongoDB Atlas 上的数据库在 Heroku 上的应用程序上进行部署,但是当我尝试注册或登录 POST 请求时,我在 Heroku 日志中收到此消息:

2020-03-29T09:54:50.197717+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/users/register" host=sleepy-beach-03876.herokuapp.com request_id=87810d90-3e72-4ff7-929e-77157f1b4a12 fwd="xxx.xxx.xxx.xxx" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https

我的尝试

  • 增加连接超时时间
  • 仔细检查我的 IP 地址是否被列入白名单,它是
  • 仔细检查 URI 是否正确,似乎正确
  • 使用 Heroku 配置变量

这是 URI
mongoURI : 'mongodb+srv://xxx:xxxxxxxx@clusterftr-wrdqy.mongodb.net/test?retryWrites=true&w=majority'

我试过了

mongoose.connect(db.mongoURI, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
})
.then(() => console.log(`MongoDB connected... ${db.mongoURI}`))
.catch(err => console.log(err + db.mongoURI));

还有这个

const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://xxx:xxxxxxxx@clusterftr-wrdqy.mongodb.net/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
  const collection = client.db("test").collection("users");
  client.close();
});


请注意,这是我在 StackOverflow 上的第一篇文章,也是我的第一个 Node 项目之一,所以如果你愿意,请理解并给我一些反馈:)

【问题讨论】:

  • 这不是你的真实密码,是吗?
  • 不,不是^^'
  • mongodb+srv 仅支持 3.6+ 驱动,你可以尝试使用旧式连接字符串,看看是否有区别。
  • 感谢您的回复,我将URI格式更改为旧格式,但显然我仍然遇到同样的问题
  • 检查白名单以确保允许 Heroku IP。

标签: node.js mongodb heroku mongodb-atlas


【解决方案1】:

我重新启动了我的测功机,它对我有用 Please Check this Heroku Application Image

【讨论】:

    【解决方案2】:

    不知道这有多相关,但我收到了H12 - Request Timeout 错误。很可能是因为在 Heroku 中无法访问我的 .env 变量。

    在我的应用程序的设置菜单中,我将它们添加到 Config Vars 部分,现在它已连接。

    【讨论】:

      【解决方案3】:

      好的,如果有人遇到同样的问题,我会回复我自己的帖子。

      我只是忘记在白名单中添加 Heroku IP,以便他们可以访问数据库...

      【讨论】:

      • 我遇到了同样的问题。我正在使用名为PROXIMO(在 Heroku 中)的插件,它生成一个 IP。我把它,即xx.xx.xx.155 变成了MongoDB atlas > Network Access > IP Whitelist。我还有什么需要做的吗?
      • 嗨,我不知道这个插件,但也许有办法让你找到你正在使用的 Heroku 服务器的 IP。我的项目只是一个小的个人项目,所以我只是放了 0.0.0.0 以允许 Heroku 连接。
      猜你喜欢
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 2012-07-08
      • 1970-01-01
      • 2019-12-15
      • 2020-01-26
      相关资源
      最近更新 更多