简体   繁体   English

MongoDB与远程服务器的连接

[英]MongoDB connection to remote server

I am using a remote mongoDB server. 我正在使用远程mongoDB服务器。 When I connected with username and password using Robo3T It will successfully connected(ssh). 当我使用Robo3T连接用户名和密码时,它将成功连接(ssh)。

However when I use it in my node server it will gives following error. 但是,当我在节点服务器中使用它时,它将给出以下错误。

Code

mongoose.Promise = require('bluebird');
mongoose.connect('mongodb://156.6*.***.***:22/TestDB',
{user:'root', pass:'********', useMongoClient: true} , 
error => {
console.log(error);
}
 );

Error 错误

{ 
  err: 'socketHandler',
  trace: '',
  bin: undefined,
  parseState:
   { 
     sizeOfMessage: 759714643,
     bytesRead: undefined,
     stubBuffer: undefined
   } 
}
Unhandled rejection (<{"err":"socketHandler","trace":"","par...>, no stack trace)

I tried so many ways. 我尝试了很多方法。 But always it returns that error. 但是总会返回该错误。 How can I solve this problem?. 我怎么解决这个问题?。

Try changing pass to password 尝试将pass更改为password

mongoose.Promise = require('bluebird');
mongoose.connect(
  'mongodb://156.6*.***.***:22/TestDB',
  {
    auth: {
      user:'root',
      password:'********',
    },
    useMongoClient: true
  },
  err => {
    console.log(err);
  },
);

I've also added a log to catch any error which may be thrown. 我还添加了一个日志来捕获可能引发的任何错误。 Let us know the output of that if it doesn't work. 让我们知道它的输出,如果它不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM