Matheus Henrique
Matheus Henrique

Reputation: 11

MongoTimeoutError: Server selection timed out after 30000 ms, using heroku to deploy

I need your help to connect my mongodb database to the cluster atlas, I configured my IP, username and password. I'm using heroku to deploy. Thanks for help! But I can't , see bellow:

express: "^4.17.1", express-session: "^1.17.0", mongoose: "^5.8.3",

const mongoose = require('mongoose');
const db = { mongoURI: 'mongodb+srv://username:[email protected]/test?retryWrites=true&w=majority' }    
    mongoose.Promise = global.Promise;
    mongoose.connect(db.mongoURI, {
      useUnifiedTopology: true,
      useNewUrlParser: true
      }).then(() => {
        console.log('Successfully');
      }).catch((err) => {
        console.log('Error: ' + err);
      });

Upvotes: 1

Views: 78

Answers (2)

Matheus Henrique
Matheus Henrique

Reputation: 11

I've added my IP to the whitelist and IP anywhere but isn't working. I read the link, but I don't understand how it can me help, sorry..

Upvotes: 0

D. SM
D. SM

Reputation: 14480

You need to whitelist the server IP. See here for how to determine which IPs to whitelist.

Upvotes: 1

Related Questions