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


When I substituted localhost for 127.0.0.1 I get the following error:

~  mongoimport --host 127.0.0.1 --port 27017 --db test --collection people --file ~/Downloads/mongodb-consultas.json --jsonArray
2015-09-28T15:15:42.047-0600    connected to: 127.0.0.1:27017
2015-09-28T15:15:42.049-0600    Failed: error reading separator after document #1: bad JSON array format - found no opening bracket '[' in input source
2015-09-28T15:15:42.049-0600    imported 0 documents


The document that I am trying to import is not corrupted as I got it from a MongoDB tutorial, and it is working for other users.

My MongoDB shell version is 3.0.6.

I have a MongoDB server by running mongod in the command line. The command mongo runs fine as well.

My firewall allows incoming connections for MongoDB.
I have gone through the error and checked out, the problem is resist with mongoimport syntax. The mongoimport shell is unable to find the location of (.json) file.

And also there is mistake like --jsonArray.

As per MongoDB BOL --jsonArray Modifies the output of mongoexport to write the entire contents of the export as a single JSON array. By default mongoexport writes data using one JSON document for every MongoDB document.  


  Note:- Accepts the import of data expressed with multiple MongoDB documents within a single JSON array. Limited to imports
  of 16 MB or smaller.


For Simple mongoimport syntax will be like that

mongoimport -d databasename -c collectionname (File Location of json file.json)


For Example

mongoimport -d test -c zips C:\MongoDBDBA\zips.json

2018-02-07T08:32:31.084+0300    connected to: localhost
2018-02-07T08:32:31.532+0300    imported 29353 documents


IN the above mongoimport syntax the database name is test and collection name is zips and C:\MongoDBDBA\zips.json is the (.json) file location.

For Example with localhost and port number 27017

If you want to use localhost and by default port number 27017 in mongoimport then simply the syntax will be like that

mongoimport --host localhost --port 27017 -d blog -c posts C:\MongoDBDBA\posts.json

2018-02-07T10:48:54.340+0300    connected to: localhost:27017
2018-02-07T10:48:56.333+0300    [########################] blog.posts   33.9MB/33.9MB (100.0%)
2018-02-07T10:48:56.345+0300    [########################] blog.posts   33.9MB/33.9MB (100.0%)
2018-02-07T10:48:56.346+0300    imported 1000 documents


Here in the above syntax blog is the database name and collection name is posts.


  Most Important Note:- Run mongoimport from the system command line, not the mongo shell.


For your further ref Here