mongodb Failed: error connecting to db server: no reachable servers

A temporary workaround is to add the host param to your mongoimport call, letting mongo know that the host is your own machine (127.0.0.1):

mongoimport --host=127.0.0.1

The full command in your case is then:

mongoimport --host=127.0.0.1 \
  --db test --collection restaurants --drop --file dataset.json

(Source: ranjeetcao @ mongorestore Failed: no reachable servers)


Update:

Updating to Mongo >= 3.0.7 should solve the issue

(Source: Colin Marshall @ mongorestore Failed: no reachable servers)


Update 2:

It seems the Bug is still happening for some users.

There's also an open JIRA issue here.

(Source: James Chien @ this question thread)


Update 3:

In some cases, this can be caused by Mongo running as a ReplicaSet. To solve this, as far as I've seen, one can either disable the ReplicaSet functionality or reset it. See:

  • How to reset MongoDB replica set settings
  • How to convert a MongoDB replica set to a stand alone server

(Source: Maxim Yefremov @ mongorestore Failed: no reachable servers)


To provide the options host and port

mongoimport --host X.X.X.X --port 27017 --db dbName --collection collectionName --file fileName.json --jsonArray

Tags:

Mongodb