我正在尝试使用终端中的 mongoimports
将 JSON 文件添加到 mongodb,这里:
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。
我不确定是什么导致了导入过程的障碍??或者如何进一步调查以追查问题?
更新
simple.json
的 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。
关于mongodb - 使用 mongimport 导入 JSON 文件,不断得到 `unexpected identifier` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16500127/