我是nodejs的新手,当我尝试连接多个mongodbs,在不同的aws服务器上运行时,我遇到了一个问题。
我使用了tunnel-ssh
,但显示无法连接。
任何人都可以提供一些有关如何连接多个mongodbs的信息,在单个nodejs应用程序中的不同aws服务器上运行吗?
const fs=require('fs')
var mongoose = require('mongoose');
var tunnel = require('tunnel-ssh');
var config = {
username:'ubuntu',
host:'my.ip.address',
agent : process.env.SSH_AUTH_SOCK,
privateKey:require('fs').readFileSync('C:\Users\\Ronit\\Downloads\\my.ppk'),
port:19735,
dstHost:'Database server Ip address',
dstPort:19735,
localHost:'127.0.0.1',
//password:'mypassword',
localPort: 19735,
keepAlive:true
};
var server = tunnel(config, function (error, server) {
if(error){
console.log("SSH connection error: " + error);
}
mongoose.connect('mongodb://localhost:19735/test');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'DB connection error:'));
db.once('open', function() {
// we're connected!
console.log("DB connection successful");
});
});

events.js:141
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED my_ip:19735
at Object.exports._errnoException (util.js:873:11)
at exports._exceptionWithHostPort (util.js:896:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1077:14)