1
mongoimport --db my_db --collection mycol --file "D:\workspace\intelligent_TDR\charm\employees.json" --jsonArray

Importing the employees.json file using the above command gives me the error

Failed: error reading separator after document #1: bad JSON array format - found no opening bracket '[' in input source

The content of json file is

{"employees":[
  { "firstName":"John", "lastName":"Doe" },
  { "firstName":"Anna", "lastName":"Smith" },
  { "firstName":"Peter", "lastName":"Jones" }
]}

If I place the content within '[' and ']' the import works.

The below json is imported without error

[{"employees":[
  { "firstName":"John", "lastName":"Doe" },
  { "firstName":"Anna", "lastName":"Smith" },
  { "firstName":"Peter", "lastName":"Jones" }
]}]
1
  • Why do you use the --jsonArray option if you don't have an array as your input? Commented Jan 29, 2020 at 11:11

1 Answer 1

1

In the json file you can pass the documents like,

{"employees":
  { "firstName":"John", "lastName":"Doe" },
  { "firstName":"Anna", "lastName":"Smith" },
  { "firstName":"Peter", "lastName":"Jones" }
}

It is not required to give the documents as a list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.