1

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.

1

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

1

Check if localhost is getting telnet from command prompt.

$ telnet localhost 27017

If it is not getting connected then check /etc/hosts on your machine.

It should have uncommented entry as 127.0.0.1 localhost

0

DISCLAIMER : Very Rookie MongoDBA

My guess would be the Document Size

According to "MongoDB Limits and Thresholds"

BSON Document Size

The maximum BSON document size is 16 megabytes.

The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API. See mongofiles and the documentation for your driver for more information about GridFS.

It may have timed out looking for the end of the Document.

You should bsondump the file to a json file and check the contents for BUT DO NOT IMPORT THE RESULTING JSON because some fidelity is lost.

0

Can you show that JSON file .As per error "found no opening bracket '['" mongoimport not able to find opening bracket. So enclose whole JSON in [...] then try hopefully will work.

0

Please validate the json documents which are being imported into MongoDB collection using mongoimport

According to the above mentioned error description it seems that json file is invalid due to which mongoimport tool fails to import documents into mongo collection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.