MongoNetworkError:与[connection_url]的连接6超时

时间:2019-07-10 14:27:18

标签: node.js mongodb mongoose

Mongo连接配置

mongoose.connect(mongo.uri, {
    socketTimeoutMS: 30000,
    reconnectTries: 30000,
    connectTimeoutMS: 30000,
    keepAlive: 1,
    useNewUrlParser: true,
  });

我正在尝试使用播种机插入数据,但是我的数据非常大。 我的数据文件大小为70mb。

mongo连接URL是我的服务器mongo URL。

UnhandledPromiseRejectionWarning: MongoNetworkError: connection 6 to [connection_url] timed out
    at TLSSocket.<anonymous> (/usr/src/node_modules/mongodb-core/lib/connection/connection.js:259:7)
    at Object.onceWrapper (events.js:288:20)
    at TLSSocket.emit (events.js:200:13)
    at TLSSocket.Socket._onTimeout (net.js:432:8)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)
(node:71) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:71) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

如果有人对此有任何想法,请提供帮助。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我找到了解决此错误的方法。这不是一个完美的解决方案,但对我来说是有用的。我已将播种机数据分为多个块,然后按块插入。

const _ = require('lodash');

_.chunk([large Data Object], 500);

500 =一块中所需的数据数

希望它也对您有用!