mongodb - 使用 mongimport 导入 JSON 文件,不断得到 `unexpecte

我正在尝试使用终端中的 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。

我不确定是什么导致了导入过程的障碍??或者如何进一步调查以追查问题?

更新

  1. 有人建议将所有内容放在一条线上。一个体面的建议。我试过了,但没有用。
  2. 我尝试导入一个非常简单的名为 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/

相关文章:

mongodb - 如何在 Mongoose Schema 中表示 MongoDB GeoJSON

mongodb - 如何在 MongoDB 集合中获取特定的嵌入文档?

java - 使用 Java 将 Java 对象插入 MongoDB 集合

mongodb - 在 mongodb 和 pymongo 中测试空字符串

macos - 使用 OS X 10.10 Yosemite Beta 使用 Homebrew 重新

MongoDB Shell - 访问名称为句​​点的集合?

node.js - 创建使用 Mongoose 更新和保存文档的方法?

macos - 如何为 MongoDB 创建配置文件

mongodb - 如何在启动时为 MongoDB 容器创建数据库?

node.js - Mongoose:ObjectId 比较失败不一致