0

I use Nodejs with Mongodb connection, it works. I didn't not change anything in code . Now I can't connect to mongodb. When I try connect with Robomongo when I don't use ssh I can't connect

enter image description here

But when I try to connect with ssh I can connect. My connection is success.

enter image description here

I can't understand problem.

My nodejs mongo connection in in here:

MongoClient.connect('mongodb://username:password@ipadress/dbname', (err, database) => {
  if (err) return console.log(err)
    db = database
    app.listen(process.env.PORT || 5000, () => {
      console.log('listening on 5000')
    })
})

Thank you for help.

Oliver
  • 11,857
  • 2
  • 36
  • 42
  • It's bound to localhost. For the good. [Bad things happen](https://www.darknet.org.uk/2017/01/mongodb-ransack-33000-databases-hacked/) when you expose it to the wild. – Alex Blex Aug 04 '17 at 10:11

1 Answers1

0

Your mongodb is not listening on the external interface but on localhost only so you can't connect directly to the 139.x.x.x IP.

However, if you use SSH it will first tunnel into the host and then connect locally so it works.

Oliver
  • 11,857
  • 2
  • 36
  • 42