使用mongimport导入JSON文件,不断获得"意外标识符"?

cat*_*aki 29 mongodb mongoimport

我正在尝试使用mongoimports终端向mongodb添加一个JSON文件,这里:

 mongoimport --db my_db --collection my_collection --file /content/2_read.json
Run Code Online (Sandbox Code Playgroud)

我一直在JavaScript execution failed: SyntaxError: Unexpected identifier 通过JSON Lint运行我的JSON:http://jsonlint.com/ ,它说它是有效的JSON.

我不确定什么可能绊倒导入过程?或者如何进一步调查以追捕这个问题?

UPDATE

  1. 有人建议把所有人放在一条线上.一个体面的建议.我尝试过它并没有用.
  2. 我尝试导入一个非常简单的以simple.json内容命名的json文件{'content' : 'simple'}但是我仍然使用相同的错误mongoimport.(我可以从mongoshell 添加文件就好了.)

下面是JSON的示例.

2_read.json

{
  "name" : "John",
  "tasks" : [
      {
       "ix" : "1",
       "description" : "description of task",
       "tags": []
      }, 
     {
      "ix": "2",
      "description" : "description of task",
      "tags" : []
     }
       ]
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

cat*_*aki 125

回答我自己的问题,因为完整的新手会理解错误,并可能在开始时遇到错误.

mongoimport从终端使用,不在mongoshell中使用.就像你不使用npm里面node.; d

在弄清楚我的概念错误后,我需要@WiredArray在评论中指出@WiredPrairie.

  • 即使我犯了同样的错误.感谢分享.它节省了我的时间 (8认同)
  • 犯了同样的错误.谢谢你回答你的问题. (8认同)