Search code examples
node.jsherokumongoosemongodb-atlas

Issue when trying to connect Heroku to Atlas MongoDB


I'm trying to connect my app from Heroku to my MongoDB in Atlas. I'm getting the error below: enter image description here

Here is my connection:

mongoose.Promise=global.Promise
    mongoose.connect(process.env.MONGODB_URL, {useNewUrlParser: true, useUnifiedTopology: true}).then(()=>{
        console.log("Conectado ao Mongo")
    }).catch((err)=>{
        console.log("Erro ao Conectar ao Mongo:" + err)
    })

I've added to Heroku the variable and the connection link. I saw some tutorials saying that I should add an IP in Atlas, but where can I get the Heroku IP?

Thanks!


Solution

  • After adding the ip "0.0.0.0/0 (includes your current IP address)" and restarting the services, I was able to access the site successfully