gpt4 book ai didi

node.js - MongoDB连接错误: MongoTimeoutError: Server selection timed out after 30000 ms

转载 作者:行者123 更新时间:2023-12-04 13:36:01 24 4
gpt4 key购买 nike

我正在尝试创建一个完整的应用程序,阅读以下教程:

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

我遵循了所有步骤,然后尝试运行:

node server.js

但是我遇到了以下错误:

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)



我在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'));

有什么建议?

最佳答案

只需转到mongodb atlas管理面板。进入安全选项卡>网络访问>然后通过添加IP将其列入白名单
See this image to locate the particular menu
注意:在Google上检查您的IP,然后将其添加

关于node.js - MongoDB连接错误: MongoTimeoutError: Server selection timed out after 30000 ms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59162342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com