Sign Up

Sign In

Forget Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask question.

MongoDB connection error: MongoTimeoutError: Server selection timed out after 30000 ms

  • 1

I am trying to create a fullstack app reading the following tutorial:

https://medium.com/javascript-in-plain-english/full-stack-mongodb-react-node-js-express-js-in-one-simple-app-6cc8ed6de274

I followed all steps and then tried to run:

node server.js

But I got the following error:

MongoDB connection error: MongoTimeoutError: Server selection timed out after 30000 ms at Timeout._onTimeout (C:RNDfullstack_appbackendnode_modulesmongodblibcoresdamserver_selection.js:308:9) at listOnTimeout (internal/timers.js:531:17) at processTimers (internal/timers.js:475:7) { name: ‘MongoTimeoutError’, reason: Error: connect ETIMEDOUT 99.80.11.208:27017 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) { name: ‘MongoNetworkError’, [Symbol(mongoErrorContextSymbol)]: {} }, [Symbol(mongoErrorContextSymbol)]: {} } (node:42892) UnhandledPromiseRejectionWarning: MongoTimeoutError: Server selection timed out after 30000 ms at Timeout._onTimeout (C:RNDfullstack_appbackendnode_modulesmongodblibcoresdamserver_selection.js:308:9) at listOnTimeout (internal/timers.js:531:17) at processTimers (internal/timers.js:475:7)

My code at server.js is as follows:

const mongoose = require('mongoose');
const router = express.Router();

// this is our MongoDB database
const dbRoute =
    'mongodb+srv://user:<password>@cluster0-3zrv8.mongodb.net/test?retryWrites=true&w=majority';

mongoose.Promise = global.Promise;

// connects our back end code with the database
mongoose.connect(dbRoute, 
    {   useNewUrlParser: true,
        useUnifiedTopology: true
    });

let db = mongoose.connection;

db.once('open', () => console.log('connected to the database'));

Any suggestions?

Share This Post
Share
  1. Check out our official blog for this error. Here Is All Possible Solution For MongoDB MongoTimeoutError: Server selection timed out after 30000 ms
    https://blog.icetutor.com/how-to-solve-mongodb-mongotimeouterror-server-selection-timed-out-after-30000-ms/

    • 0
  2. Whitelist your connection IP address. Atlas only allows client connections to the cluster from entries in the project’s whitelist. The project whitelist is distinct from the API whitelist, which restricts API access to specific IP or CIDR addresses.

    NOTE

    You can skip this step if Atlas indicates in the Setup Connection Security step that you have already configured a whitelist entry in your cluster. To manage the IP whitelist, see Add Entries to the Whitelist.

    If the whitelist is empty, Atlas prompts you to add an IP address to the project’s whitelist. You can either:

    Click Add Your Current IP Address to whitelist your current IP address.

    Click Add a Different IP Address to add a single IP address or a CIDR-notated range of addresses.

    For Atlas clusters deployed on Amazon Web Services (AWS) and using VPC Peering, you can add a Security Group associated with the peer VPC.

    You can provide an optional description for the newly added IP address or CIDR range. Click Add IP Address to add the address to the whitelist.

    • 0
  3. This answer was edited.

    just go to mongodb atlas admin panel.Go in security tab>Network Access> Then whitelist your IP by adding it

    Note:Check your IP on google then add it

    • -8
Leave an answer

Leave an answer

Browse

close