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.
Best Answer
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 ofmongoexport
to write the entire contents of the export as a singleJSON
array. By defaultmongoexport
writes data using oneJSON
document for everyMongoDB
document.For Simple mongoimport syntax will be like that
For Example
IN the above
mongoimport
syntax the database name istest
and collection name iszips
andC:\MongoDBDBA\zips.json
is the (.json
) file location.For Example with localhost and port number 27017
If you want to use
localhost
and by defaultport
number27017
inmongoimport
then simply the syntax will be like thatHere in the above syntax
blog
is the database name and collection name isposts
.For your further ref Here