Konstantin Milyutin
Konstantin Milyutin

Reputation: 12366

Error during mongoimport

I have a couple of valid JSON documents and I try to import them in mongodb.

{ "Books":
  [{ "ISBN":"ISBN-0-13-713526-2",
  "Price":85,
  "Edition":3,
  "Title":"A First Course in Database Systems",
  "Authors":[ {"First_Name":"Jeffrey", "Last_Name":"Ullman"},
              {"First_Name":"Jennifer", "Last_Name":"Widom"} ] }
,
{ "ISBN":"ISBN-0-13-815504-6",
  "Price":100,
  "Remark":"Buy this book bundled with 'A First Course' - a great deal!",
  "Title":"Database Systems:The Complete Book",
  "Authors":[ {"First_Name":"Hector", "Last_Name":"Garcia-Molina"},
              {"First_Name":"Jeffrey", "Last_Name":"Ullman"},
              {"First_Name":"Jennifer", "Last_Name":"Widom"} ] }],
"Magazines":
[{ "Title":"National Geographic",
  "Month":"January",
  "Year":2009 }
,
{ "Title":"Newsweek",
  "Month":"February",
  "Year":2009 },
{"Title": "Newsweek"}]
}

I got the following error:

Sun Mar 24 15:23:27 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: "Month":"J Sun Mar 24

15:23:27 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: "Year":200 Sun Mar 24 15:28:23

ERROR: encountered 28 errors

Could someone say what's wrong?

Upvotes: 10

Views: 9005

Answers (4)

Mandeep Gill
Mandeep Gill

Reputation: 4907

If you want to import json file you can use this also

also for csv use --type csv

mongoimport --db database --collection collection_name filename.json --type json

Upvotes: 0

Enamul Hassan
Enamul Hassan

Reputation: 5445

The following command from terminal worked good for me:

mongoimport -d my_db -c my_collection < my_json_file.json --batchSize 1

Some version needs to change the --batchSize 50 instead of 1 like below:

mongoimport -d my_db -c my_collection < my_json_file.json --batchSize 50

Upvotes: 1

WiredPrairie
WiredPrairie

Reputation: 59793

By default mongoimport expects that each document will be on a single line of the JSON file. You need to pass --jsonArray to mongoimport using the format you're using, or just make sure that all of the data for a single document is on one line.

(I saved your file, as is, added the --jsonArray, option and it worked fine.)

Upvotes: 31

Michal
Michal

Reputation: 2084

MongoDB has limit of 16 MB per document. If you want to overcome this limit you need to use GridFS. Plese look at documentation here.

Upvotes: 1

Related Questions