我试图从终端使用mongoimports
添加JSON文件到mongodb,在这里:
mongoimport --db my_db --collection my_collection --file /content/2_read.json
我一直得到JavaScript execution failed: SyntaxError: Unexpected identifier
我通过JSON Lint: http://jsonlint.com/运行我的JSON,它说它是有效的JSON。
我不确定是什么阻碍了进口过程?或者如何进一步调查找出问题所在?
- 有人建议把所有放在一行。一个不错的建议。我试过了,但没有用。
- 我尝试导入一个非常非常简单的json文件名为
simple.json
与内容{'content' : 'simple'}
,但我仍然得到同样的错误使用mongoimport
。(我可以从mongo
shell添加文档)
JSON示例如下:
2 _read。json
{
"name" : "John",
"tasks" : [
{
"ix" : "1",
"description" : "description of task",
"tags": []
},
{
"ix": "2",
"description" : "description of task",
"tags" : []
}
]
}
谢谢。
回答我自己的问题,因为完整的新手将欣赏这个错误,并可能在他们开始时遇到它。
mongoimport
在终端中使用,而不是在mongo
shell中使用。就像你不在node
里面使用npm
一样。; D
在弄清楚我的概念错误之后,我需要@WiredPrairie在评论中指出的—jsonArray。
下面的命令在终端上运行良好:
mongoimport -d my_db -c my_collection < /content/2_read.json --batchSize 1