Maxim Yefremov
Maxim Yefremov

Reputation: 14175

mongorestore Failed: no reachable servers

I tried to restore mongo from dump but failed:

mongorestore --port 27133 dump
2015-05-07T09:39:11.760+0300    Failed: no reachable servers

Although I can connect to it without any problem:

$ mongo --port 27133
MongoDB shell version: 3.0.1
connecting to: 127.0.0.1:27133/test

In a log file there is nothing special:

2015-05-07T09:37:00.350+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44901 #1 (1 connection now open)
2015-05-07T09:37:13.935+0300 I NETWORK  [conn1] end connection 127.0.0.1:44901 (0 connections now open)
2015-05-07T09:39:08.752+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44906 #2 (1 connection now open)
2015-05-07T09:39:11.763+0300 I NETWORK  [conn2] end connection 127.0.0.1:44906 (0 connections now open)
2015-05-07T09:39:52.365+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44907 #3 (1 connection now open)
2015-05-07T09:39:55.064+0300 I NETWORK  [conn3] end connection 127.0.0.1:44907 (0 connections now open)
2015-05-07T09:40:11.272+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44909 #4 (1 connection now open)
2015-05-07T09:40:14.281+0300 I NETWORK  [conn4] end connection 127.0.0.1:44909 (0 connections now open)

Update

Host 127.0.0.1 didn't help

$ mongorestore --host=127.0.0.1 --port=27132 dump
2015-12-16T18:52:33.270+0300    Failed: no reachable servers

Although I can still connect using mongo command:

$ mongo --host=127.0.0.1 --port=27133
MongoDB shell version: 3.2.0
connecting to: 127.0.0.1:27133/test
> ^C
bye

Host 0.0.0.0 didn't help as well:

$ mongorestore --host=0.0.0.0 --port=27133 dump

I have 3.2 version of MongoDb:

$ mongorestore --version
mongorestore version: 3.2.0-rc5
git version: 6186100ad0500c122a56f0a0e28ce1227ca4fc88

Upvotes: 51

Views: 68227

Answers (14)

socrates
socrates

Reputation: 1323

This is mostly a mongo-database-tools version issue.

I encountered the issue with a 3.x mongo-tools with a mongo:latest server container(7.x). The mongo shell worked, but mongorestore reported error

Failed: error connecting to db server: no reachable servers

or when I specify the target db with uri

mongorestore --uri mongodb://127.0.0.1:27017/ ./

The command simply hung there.

After I download the latest mongo-database-tools from https://www.mongodb.com/try/download/database-tools , everything worked. Changing the --uri, adding --host and --port parameters, altering 127.0.0.1 with docker IP like 172.17.0.x, none of them is required.

Upvotes: 0

Nimish Agrawal
Nimish Agrawal

Reputation: 571

For me the issue was in version of mongorestore

Earlier when I was using an old version mongorestore version: built-without-version-string it was giving me no reachable servers, even after adding all host and port options.

Switching to version mongorestore version: 100.6.0 - the same command worked

Upvotes: 2

Rotem jackoby
Rotem jackoby

Reputation: 22148

I struggled with the same issue while using MongoDB Atlas for a few hours.

I tried to follow the offical guides like Seed with mongorestore and Load File with mongoimport but received the same no reachable servers error.

I tried to change the command arguments over and over - nothing changed.

But then I navigated inside my cluster to the "Command Line Tools" tab and saw the exact command I should run for mongorestore, mongodump, mongoimport,mongoexport etc':

enter image description here

Adding as inline the full command:

mongorestore --host 
<cluster-name>-shard-0/
<cluster-name>-shard-00-00-obe3i.mongodb.net:27017,
<cluster-name>-shard-00-01-obe3i.mongodb.net:27017,
<cluster-name>-shard-00-02-obe3i.mongodb.net:27017 
--ssl 
--username <User-Name> 
--password <PASSWORD> 
--authenticationDatabase admin 

The mongorestore comand can be replaced with mongodump,mongoimport,mongoexport etc'.

(*) Prefer copying the command directly from dashboard because the DNS of the replica-sets might change.

(**) MongoDB shell version v4.2.5.

Upvotes: 5

user10898116
user10898116

Reputation:

If you're using a hosted service (like MongoDB Atlas), make sure you've set up the IP white-list so that it isn't blocking your IP address. You can set it to 0.0.0.0/0 to whitelist all IP addresses, but this is a bad idea in terms of security so it should only be used as a temporary measure.

Upvotes: 0

Dere Sagar
Dere Sagar

Reputation: 1808

In my case, I am defining port two times.

mongorestore --noIndexRestore --host X.X.X.X:27017 -d XYZ --port 27017 foldername

Solve in my case,

mongorestore --noIndexRestore --host X.X.X.X -d XYZ --port 27017 foldername

Upvotes: 0

Neil Mayhew
Neil Mayhew

Reputation: 14917

In my case (with Mongo 3.2.9), the server was configured to listen on the IPv4 localhost address (127.0.0.1) but mongorestore tried only the IPv6 localhost address (::1).

Using -h 127.0.0.1 worked. However, this shouldn't be necessary, IMHO, and is a bug in mongorestore. It should use the same connection logic as the mongo command-line client, which was working.

Note: replica sets were not enabled.

Upvotes: 2

Huy Truong
Huy Truong

Reputation: 11

I have the same problem. I tried to start mongod before restoring my dump, and it work for me. Hope this help this situation

Upvotes: 0

Shi Jieming
Shi Jieming

Reputation: 551

Do you run mongo in replica set, i.e., mongod --replSet rs0?

If yes, please remember to run in your mongo shell the command: rs.initiate()

Then you can use cmd mongorestore to restore your db.

Upvotes: 25

Liz
Liz

Reputation: 71

I had difficulty with that question also.

mongorestore --host f8cab83e7294 --port 27601 gene_backup_final/gene_backup/s2/  --verbose

2016-12-05T13:48:15.333-0700 Failed: error connecting to db server: no reachable servers

I failed to initiate the replica set. That is why there was no reachable server

After initiating the RS, restore worked.

mongo localhost:27501
rs.initiate()

Upvotes: 2

Phily Austria
Phily Austria

Reputation: 11

First run mongod

If you get exception exception in initAndListen: 29 Data directory /data/db not found., terminating, do sudo mkdir -p /data/db

If you get expection exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating, This probably you have the permission issue. If this is your local, you can run sudo chmod 7777 /data/db to fix the issue.

Now, mongod should work. Then, run mongorestore dump where your dump file is.

You should successfully restore the dump file.

Upvotes: 1

Maxim Yefremov
Maxim Yefremov

Reputation: 14175

The problem occured because --replSet was enabled in configuration. But the node wasn't yet in any replica set.

After I removed --replSet from configuration, relaunched mongodb server, mongorestore started to work without any --host parameter.

Upvotes: 25

Colin Marshall
Colin Marshall

Reputation: 2142

I have MongoDB installed through Homebrew, and was having this issue. Here are the symptoms:

These failed:

mongorestore dump

mongorestore dump --host=localhost

The error I got: Failed: error connecting to db server: no reachable servers

These worked (as a workaround):

mongorestore dump --host=127.0.0.1

mongorestore dump --host=0.0.0.0

This fixed the problem for me:

brew update && brew upgrade

That updated MongoDB to 3.0.7 and now mongorestore dump works without the host flag.

Upvotes: 17

ranjeetcao
ranjeetcao

Reputation: 1853

try adding host param

mongorestore --host=127.0.0.1 --port=27133 dump

Upvotes: 51

Prashanth Kumar B
Prashanth Kumar B

Reputation: 576

check your mongod configuration file, if you have enabled replication disable it, if enabled, key based authentication disable it basically disable every other thing and restart the mongod service and then try doing mongo restore.

And BTW, try binding mongod ipaddress to your machine address as well, if it is a local mongod instance try binding the ip address to 0.0.0.0, in mongod.conf file under bind_ip="your ip address", do let me know it does or does not.

Upvotes: 4

Related Questions