3

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!

Community
  • 1
  • 1
German
  • 496
  • 1
  • 4
  • 10
  • This indicates that either the server is no running or you have a firewall rule blocking access to the port. Most likely it is not actually running. Try basically connecting the `mongo` shell and check the running status of the server. – Blakes Seven Sep 28 '15 at 04:13
  • @BlakesSeven I am also running mongo, it shows "connecting to: test" and some other information. How can I determine if the firewall is blocking access to the port? – German Sep 28 '15 at 04:28
  • @BlakesSeven I just checked and the firewall allows incoming connections for mongod... – German Sep 28 '15 at 05:13
  • What happens if you use `127.0.0.1` instead of localhost? Furthermore, this question should have been asked on http://dba.stackexchange.com – Markus W Mahlberg Sep 28 '15 at 08:12
  • @MarkusWMahlberg yeah that does not work either... I get the following error instead `Failed: error reading separator after document #1: bad JSON array format - found no opening bracket '[' in input source`. The file that I am trying to import is not corrupted as I got it from a tutorial. Thanks for the suggestion, I didn't know about dba.stackexchange.com. I will try asking for help there as well. – German Sep 28 '15 at 21:22
  • @German Its an either here **or** there thing. Basically, you have a connection now. Please add the output of `head -c20 yourfile.json` to your question by editing it. – Markus W Mahlberg Sep 29 '15 at 07:58

6 Answers6

3

You need to use --host 127.0.0.1:27017

1

Try changing --host localhost to --host 127.0.0.1

SneakyMummin
  • 683
  • 1
  • 11
  • 30
1

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

ARoy
  • 19
  • 4
0

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.

Ramesh Murugesan
  • 4,727
  • 7
  • 42
  • 67
0

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.

Pedro Otero
  • 324
  • 5
  • 15
0

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.

Rot-man
  • 18,045
  • 12
  • 118
  • 124