I have the following json data I am trying to import into mongodb.
{
"subjectId": "63cd96779e66d518f3af574c",
"name":"Earth and Space Science",
"subtopics": [
{
"name": "Rocks, Soil and Minerals",
"questions": [
{
"question": "What type of rock is formed when magma cools and hardens?",
"multipleChoice":["Sedimentary", "Metamorphic", "Igneous", "All of the above"],
"answer": "Igneous"
}
]
}
]
}
I am getting the error: Operation passed in cannot be an array.
Do you know why?
CodePudding user response:
Maybe, the Problem is the formatted json structure with you tabs and spaces, it has to be unformatted in a Oneliner.
Try this:
{"subjectId":"63cd96779e66d518f3af574c","name":"Earth and Space Science","subtopics":[{"name":"Rocks, Soil and Minerals","questions":[{"question":"What type of rock is formed when magma cools and hardens?","multipleChoice":["Sedimentary","Metamorphic","Igneous","All of the above"],"answer":"Igneous"}]}]}
Refer to this.
CodePudding user response:
MongoDB Compass has an unusual JSON file import format requirement in that each document must be delimited by a newline.
When importing data from a JSON file, you can format your data as:
- Newline-delimited documents, or
- Comma-separated documents in an array
After formatting your JSON document file as required, MongoDB Compass imports your file normally. Hopefully Compass's file import parser will become "smarter".