Dump remote database: Failed: error connecting to db server: no reachable servers

SoftTimur picture SoftTimur · Nov 20, 2017 · Viewed 7.1k times · Source

I have a database in www.myweb.io, which has SSL. The version of mongo is 2.6.12 in the server: the version of mongo in local is 3.4.1. I want to dump it into my local machine, modify it, and then restore back.

I tried

mongodump --host www.myweb.io --port 22 --username myname --password "mypassword"

and it gave me an error:

2017-11-20T20:57:07.775+0100    Failed: error connecting to db server: no reachable servers

Does anyone know what host and post I should set?

PS: in my localhost, I can use the following setting in Robo 3T to connect to the database:

1) under Connection, specify localhost:27017

2) under SSH, check Use SSH tunnel, specify xxx.xx.xx.xx:22 as SSH Address

In /etc/nginx/sites-enabled/myweb.io, there is listen 443 ssl.

Answer

Zarathustra picture Zarathustra · Jan 31, 2018
  1. you are not connecting via SSL or TLS to the database.

  2. Use an ssh tunnel to establish a connection to your mongodb

    ssh -N -L 27018:localhost:27017 [email protected]

you can specify -f to let ssh go in the background

  1. Verify that the tunnel is working

Using mongodb

mongo --port 27018

Or telnet

telnet localhost 27018
  1. dumping the database

    mongodump --host 127.0.0.1 --port 27018 --db <dbName>

  2. restore it somewhere, do your modifications

  3. dump your local modifications

  4. reapply the local modifications remote for example with mongorestore or mongoimport