I am unable to connect my Node.js app deployed to Heroku with a MongoDB database. It works fine on localhost, but not on Heroku.
In my logs, I see this:
MongoNetworkError: failed to connect to server [authproject-shard-00-01-ybey8.mongodb.net:27017] on first connect [MongoNetworkError: connection 4 to authproject-shard-00-01-ybey8.mongodb.net:27017 closed]
custom-environment-variables.json:
{
"db": "Auth_db"
}
default.json:
{
"db": "mongodb://localhost/user"
}
db.js:
const db = config.get("db");
mongoose
.connect(db)
.then(() => console.log("connected to mongodb.."))
.catch(err => console.error("could not connect to mongodb", err));
};