我正在尝试设置基本的 mongodb 连接,但出现ECONNRESET
错误。我进行了一些研究,发现了类似的问题和答案,但还没有找到解决方案。
代码:
'use strict';
const Hapi = require('hapi');
const hapiMongo = require('hapi-mongodb');
var server = new Hapi.Server();
server.connection({
port: '1111'
});
server.route({
method: 'GET',
path: '/',
config: {
cors: true,
handler: (request, reply) => {
var db = request.server.plugins['hapi-mongodb'].db;
reply('Hello World' + db);
}
}
});
server.register({
register: hapiMongo,
options: {
"url": "mongodb://username:psswd@ds011308.mongolab.com:11308/heroku_jg542kf4",
"settings": {
"db": {
"native_parser": false
}
}
}
}, (err) => {
if (err) {
console.error(err);
throw err;
}
server.start((err) => console.log('Served at:', server.info.uri));
})
控制台错误:
{ [MongoError: 服务器 ds011308-a.mongolab.com:11308 收到错误 {"name":"M ongoError","message":"read ECONNRESET"}] 名称:'MongoError',消息:'server ds011308-a .mongolab.com:11308 收到错误 {"name":"Mong oError","message":"read ECONNRESET"}' }
C:\Users\username\Desktop\code\hapi-mongo\node_modules\mongodb\lib\mongo_client.js:4 54 throw err ^ MongoError: server ds011308-a.mongolab.com:11308 received an error {"name": "Mon goError","message":"read ECONNRESET"} 为 null。(C:\Users\username\Desktop\code\hapi-mongo\node_modules\mong odb-core\lib\topologies\server.js:297:40) at emitTwo (events.js:87:13) at emit (events .js:172:7) 为空。(C:\Users\username\Desktop\code\hapi-mongo\node_modules\mong odb-core\lib\connection\pool.js:132:12) at g (events.js:260:16) at emitTwo (events .js:87:13) 在 Socket 上发出 (events.js:172:7)。(C:\Users\username\Desktop\code\hapi-mongo\node_modules\mo ngodb-core\lib\connection\connection.js:132:49) 在 Socket.g (events.js:260:
关于如何解决这个问题的任何指示?