简体   繁体   中英

Unable to connect to the database Heroku nestjs mongoose

I am trying to deploy my nestjs project to heroku. But I keep having a timout error when connecting to 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

The weird thing is it's mongodb atlas cluster ( on the cloud ) and when I try to reach it from my machine it's all good...

It's an url that look like something like this : mongodb+srv://myDbUserName:myPassword@cluster0-opbo3.gcp.mongodb.net/test?retryWrites=true&w=majority

I tried to pass directly the uri in MongooseModule like this MongooseModule.forRoot(CONFIG.MONGODB_URI) which works again from my machine... But not heroku...

I also tried to add MONGODB_URI as env variable in heroku and use it : process.env.MONGODB_URI but no luck with that.

What am I missing ?

If you have any idea ! Thank you guys !

I finally manage to find what was wrong.

In the mongo Atlas interface only my locale machine ip was white listed.

I have open the cluster to any ip, for now. And it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM