I am trying to create a fullstack app reading the following tutorial:
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:\RND\fullstack_app\backend\node_modules\mongodb\lib\core\sdam\server_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:\RND\fullstack_app\backend\node_modules\mongodb\lib\core\sdam\server_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 databaseconst 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 databasemongoose.connect(dbRoute, { useNewUrlParser: true, useUnifiedTopology: true });let db = mongoose.connection;db.once('open', () => console.log('connected to the database'));
Any suggestions?