I'm trying to add a JSON file to mongodb using mongoimports
from terminal, here:
mongoimport --db my_db --collection my_collection --file /content/2_read.json
I keep getting JavaScript execution failed: SyntaxError: Unexpected identifier
I ran my JSON through JSON Lint: http://jsonlint.com/ which says it's valid JSON.
I'm not sure what could be tripping up the import process?? Or how to investigate further to hunt down the issue?
UPDATE
simple.json
with the content {'content' : 'simple'}
But I'm still getting the same error using mongoimport
. (I can add documents from mongo
shell just fine.) A sample of the JSON is below.
2_read.json
{
"name" : "John",
"tasks" : [
{
"ix" : "1",
"description" : "description of task",
"tags": []
},
{
"ix": "2",
"description" : "description of task",
"tags" : []
}
]
}
Thanks.
If you have CSV files (or TSV files - they're conceptually the same) to import, use the --type=csv or --type=tsv option to tell mongoimport what format to expect. Also important is to know whether your CSV file has a header row - where the first line doesn't contain data - instead it contains the name for each column.
The process to import JSON into MongoDB depends on the operating system and the programming language you are using. However, the key to importing is to access the MongoDB database and parsing the file that you want to import. You can then go through each document sequentially and insert into MongoDB.
The mongoimport command is used to import your content from an extended JSON, CSV, or TSV export created by mongoexport.
Answering my own question because complete newbies will appreciate the error and may run into it as they get started.
mongoimport
is used from terminal, NOT within the mongo
shell. Just like you don't use npm
inside node
. ;D
After figuring out my conceptual error there, I needed --jsonArray as pointed to by @WiredPrairie in the comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With