MongoError:与本地主机的连接0:27017超时

编程入门 行业动态 更新时间:2024-10-09 00:48:30
本文介绍了MongoError:与本地主机的连接0:27017超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 events.js:141 throw er; // Unhandled 'error' event MongoError: connection 0 to localhost:27017 timed out at Function.MongoError.create (/home/ubuntu/scripts/node_modules/mongodb-core/lib/error.js:29:11) at Socket.<anonymous> (/home/ubuntu/scripts/node_modules/mongodb-core/lib/connection/connection.js:184:20) at Socket.g (events.js:260:16) at emitNone (events.js:67:13) at Socket.emit (events.js:166:7) at Socket._onTimeout (net.js:318:8) at _runOnTimeout (timers.js:524:11) at _makeTimerTimeout (timers.js:515:3) at Timer.unrefTimeout (timers.js:584:5)

嗯,连接过程中没有错误,但是当尝试保存某些模型/集合时,它会运行一段时间,然后抛出此错误. 顺便说一句,我还有另一个连接到同一mongodb服务器的节点进程.任何帮助都将受到高度赞赏.

Well there is no error during connection, but when try to save some models/collections it runs for a while and then it throws this error. BTW I also have another node process connected to the same mongodb server. Any help is highly appreciated.

推荐答案

const mongoose = require('mongoose'); const option = { socketTimeoutMS: 30000, keepAlive: true, reconnectTries: 30000 }; const mongoURI = process.env.MONGODB_URI; mongoose.connect(mongoURI, option).then(function(){ //connected successfully }, function(err) { //err handle });

更多推荐

MongoError:与本地主机的连接0:27017超时

本文发布于:2023-11-26 21:37:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:与本   主机   MongoError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!