使用mongimport导入JSON文件,继续获取“意外标识符"吗? [英] Importing JSON file using mongimport, keep getting `unexpected identifier`?
问题描述
我正在尝试使用终端上的mongoimports
将JSON文件添加到mongodb中:
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
我不断得到JavaScript execution failed: SyntaxError: Unexpected identifier
我通过JSON Lint运行了JSON: http://jsonlint.com/它表示有效的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?
更新
- 有人建议将所有内容放在一行上.一个体面的建议.我试过了,但是没有用.
- 我尝试导入名为
simple.json
且内容为{'content' : 'simple'}
的非常简单的json文件,但是使用mongoimport
仍然会遇到相同的错误. (我可以从mongo
外壳中添加文档就可以了.)
- Somebody suggested putting all on one-line. A decent suggestion. I tried it and it didn't work.
- I tried importing a very very simple json file named
simple.json
with the content{'content' : 'simple'}
But I'm still getting the same error usingmongoimport
. (I can add documents frommongo
shell just fine.)
下面是一个JSON示例.
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" : []
}
]
}
谢谢.
推荐答案
回答我自己的问题,因为完整的新手会理解该错误,并可能在开始使用时遇到错误.
Answering my own question because complete newbies will appreciate the error and may run into it as they get started.
mongoimport
是从终端使用的,而不是在mongo
shell中使用的.就像您不在node
中使用npm
一样. ; D
mongoimport
is used from terminal, NOT within the mongo
shell. Just like you don't use npm
inside node
. ;D
弄清楚那里的概念错误后,我需要--jsonArray,如@WiredPrairie在评论中所指出的.
After figuring out my conceptual error there, I needed --jsonArray as pointed to by @WiredPrairie in the comments.
这篇关于使用mongimport导入JSON文件,继续获取“意外标识符"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!