我想通过nodejs使用ssh用户名/密码连接到Mongodb,代码如下:
var mongoose = require('mongoose');
var tunnel = require('tunnel-ssh');
var config = {
username : 'xyz',
host: 'xx-xxx-xx.com',
port:22,
password:'xxx',
dstPort:27017,
localPort:27017
};
console.log(tunnel);
var server = tunnel(config, function (error, server) {
if(error){
console.log("SSH connection error: " + error);
}
console.log(server);
mongoose.connect('mongodb://localhost:27017/myDB');
var db = mongoose.connection;
console.log(db);
db.on('error', console.error.bind(console, 'DB connection error:'));
db.once('open', function() {
console.log("DB connection successful");
});
});
但是我收到了以下错误:
数据库连接错误:{ MongoError: 连接到localhost:27017的连接超时
这里出了什么问题?