【发布时间】:2017-05-14 16:09:03
【问题描述】:
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 服务器。非常感谢任何帮助。
【问题讨论】:
-
添加有关 event.js 文件的详细信息
-
我认为是events.js(eventEmitter类)中内置的nodejs。我不知道它在哪里。
-
如果您的查询花费了很长时间(几秒钟),那么您的系统中存在严重缺陷,或者您正在做更多通常 API 应该做的事情。尝试在 mongo 集合中使用索引来提高性能。
-
当查询“长/重”(2s-5s)但不够长以至于它实际上应该触发默认超时 30s 时,有些人会收到此错误。对我来说,当我从 ≥mongoose-4.11 切换到
useMongoClient: true时,这种情况就消失了。