无法连接到数据库Heroku nestjs mongoose



我正在尝试将我的nestjs项目部署到heroku。但我在连接mongoDB 时一直有一个超时错误

2020-03-08T21:53:43.192716+00:00 app[web.1]: [31m[Nest] 54   - 
[39m03/08/2020, 9:53:43 PM   [38;5;3m[MongooseModule] [39m[31mUnable to connect to the database. 
Retrying (1)...[39m[38;5;3m +30084ms[39m
2020-03-08T21:53:53.398546+00:00 heroku[web.1]: State changed from starting to crashed
2020-03-08T21:53:53.308228+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

奇怪的是,它是mongodb atlas集群(在云上(,当我试图从我的机器上访问它时,一切都很好。。。

这是一个看起来像这样的url:mongodb+srv://myDbUserName:myPassword@cluster0-opbo3.gcp.mongodb.net/test?retryWrites=true&w=majority

我试图直接传递MongooseModule中的uri就像这个MongooseModule.forRoot(CONFIG.MONGODB_URI),它在我的机器上再次工作。。。但不是heroku。。。

我还尝试在heroku中添加MONGODB_URI作为env变量,并使用它:process.env.MONGODB_URI,但没有成功。

我错过了什么?

如果你有任何想法!谢谢你们!

我终于找到了问题所在。

在mongo Atlas界面中,只有我的本地机器ip被列入白名单。

目前,我已经向任何ip开放了集群。它奏效了。

最新更新