简体   繁体   中英

Node JS mongoose cannot connect to remote mongodb server

The script inside VM 192.168.26.103 is trying to connect to MongoDB on VM 192.168.26.104

But getting 'ECONNREFUSED' error

var mongoose = require('mongoose');

var dbConnect = mongoose.createConnection('mongodb://192.168.26.104:27017/test', {
    db: { safe: true }
})

Error:

{ name: 'MongoError', message: 'connect ECONNREFUSED' }

I solved the issue myself. Posting the solution below so someone might find helpfull.

In remote MongoDB server 192.168.26.104 i changed the bind_ip and now my script can connect to it successfully

/etc/mongod.conf

From bind_ip = 127.0.0.1

To bind_ip = 192.168.26.104

service mongod restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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