我正在尝试创建一个完整的应用程序,阅读以下教程:
我遵循了所有步骤,然后尝试运行:
node server.js
但我收到以下错误:
MongoDB连接错误:MongoTimeoutError:服务器选择在超时30000毫秒后超时._onTimeout(C:\ RND \ fullstack_app \ backend \ node_modules \ mongodb \ lib \ core \ sdam \ server_selection.js:308:9)在listOnTimeout(内部/ processTimers(internal / timers.js:475:7)上的timers.js:531:17){名称:“ MongoTimeoutError”,原因:错误:在TCPConnectWrap.afterConnect上连接ETIMEDOUT 99.80.11.208:27017 [完成时](网络。 js:1128:14){名称:'MongoNetworkError',[Symbol(mongoErrorContextSymbol)]:{}},[Symbol(mongoErrorContextSymbol)]:{}}(节点:42892)UnhandledPromiseRejectionWarning:MongoTimeoutError:服务器选择在30000 ms之后超时在超时时._onTimeout(C:\ RND \ fullstack_app \ backend \ node_modules \ mongodb \ lib \ core \ sdam \ server_selection.js:308:9)在processTimers(internal / timers.js:475:7)在listOnTimeout(internal / timers.js:531:17)
我在server.js上的代码如下:
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'));
有什么建议么?
user:password
为username and password
in连接字符串?