German
German

Reputation: 506

mongoimport error - Failed: error connecting to db server: no reachable servers

I am currently trying to learn mongodb and I am having trouble finding a solution for this problem. When I run a mongoimport command it I get the following error:

~ mongoimport --host localhost --port 27017 --db test --collection people --file ~/Downloads/mongodb-consultas.json --jsonArray
2015-09-27T20:46:03.228-0600    [........................] test.people  0.0 B/684.2 KB (0.0%)
2015-09-27T20:46:03.745-0600    Failed: error connecting to db server: no reachable servers
2015-09-27T20:46:03.745-0600    imported 0 documents

I have a mongodb server by running mongod in the command line.

My MongoDB shell version is 3.0.6.

Thank you!

Upvotes: 3

Views: 15022

Answers (6)

Rotem jackoby
Rotem jackoby

Reputation: 22158

Adding the an answer for those who are struggling with the same issue while using MongoDB Atlas.

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: 0

Pedro Otero
Pedro Otero

Reputation: 334

Old but since this doesn't have an answer yet:

I had the same issue and looked at all the questions and none contained the solution to my specific problem. I had created my user in the "admin" database, which I had to specify when calling mongoimport with the --authenticationDatabase argument. Can check all the arguments here.

Upvotes: 1

Ramesh Murugesan
Ramesh Murugesan

Reputation: 5013

For me, mongo cluster is ssl enabled so I had a problem to connect mongo servers. I just add --ssl it works fine. It might be helpful for someone.

Upvotes: 0

Fernando Gonzalez
Fernando Gonzalez

Reputation: 183

You need to use --host 127.0.0.1:27017

Upvotes: 4

ARoy
ARoy

Reputation: 19

The -h 127.0.0.1 parameter is a quick workaround, but upgrading to MongoDB 3.0.7 fixes this problem.

Upvotes: 1

SneakyMummin
SneakyMummin

Reputation: 711

Try changing --host localhost to --host 127.0.0.1

Upvotes: 1

Related Questions