【问题标题】:Export database from MongoDb atlas to the local machine Monogo compass将数据库从 MongoDb atlas 导出到本地机器 Monogo compass
【发布时间】:2020-05-03 08:01:17
【问题描述】:

我在 Atlas 中有名为“test”的远程数据库,我想将集合名称 image_table 下载为 JSON 文件。

在mac终端中:

$ mongoexport –db test –collection image_table image.json 我得到了错误>

020-01-16T13:49:12.822+0100 解析命令行选项时出错:位置参数太多:[–db test –collection image_table image.json] 2020-01-16T13:49:12.822+0100 尝试“mongoexport --help”以获取更多信息

【问题讨论】:

  • 您是否运行过 'mongoexport --help' 以获得更多信息。

标签: json mongodb mongodb-atlas mongodb-compass mongoexport


【解决方案1】:

MongoDB Compass 有很多缺陷,即使是导出集合这样微不足道的任务,也可能会让你失败。例如。它将跳过导出中的某些字段。该应用程序本身说:“显示的字段来自集合中的样本文档......”。根据我的经验,Compass 使用的样本非常小。即使导出 100 个左右的文档,我也会丢失数据。

使用mongoexport 很容易。如果您使用 mongo 3.6+,这将起作用:

mongoexport --uri mongodb+srv://<username>@atlas-cluster-url.mongodb.net/<db-name> --collection <collection-name> --out <path-to-export>

【讨论】:

    【解决方案2】:

    我可以在 Mongo Compass 中找到更直接的答案:

    只需安装 mongo compass 连接到您的 atlas 远程数据库:从您的远程 altas 集群中获取类似“cluster0-shard-00-00-rcapo.mongodb.net XXXXX”的主机名,然后连接到数据库。

    然后您可以将每个文档下载为 JSON 或 CSV 格式。 谢谢,mongo DB compass 开发团队。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题。在我的例子中,我使用带有 --query 选项的 mongoexport,它需要一个 JSON 文档,例如:

      mongoexport ... --query {field: 'value'} ...
      

      我需要用引号将文档括起来:

      mongoexport ... --query "{field: 'value'}" ...
      
      

      【讨论】:

        【解决方案4】:

        我想将我的地图集中的所有集合导出到本地数据库。在遇到很多关于 mongodb compass 和 mongoshell 的问题后,我最终为 mongodb 使用了 NOSQL booster。 Downloading Link

        它可以轻松地一次导出所有集合,然后我可以使用相同的工具将它们导入本地 mongodb 数据库。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-13
          • 1970-01-01
          相关资源
          最近更新 更多