将 Mongo 集合转储为 JSON 格式
有没有办法将 mongo 集合转储为 json 格式?无论是在 shell 上还是使用 java 驱动程序。我正在寻找性能最好的一个。
Is there any way to dump mongo collection into json format? Either on the shell or using java driver.I am looking for the one with best performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Mongo 包含一个 mongoexport 实用程序(请参阅文档),它可以转储集合。该实用程序使用本机 libmongoclient,可能是最快的方法。
也有帮助:
-o
:将输出写入文件,否则使用标准输出(docs)--jsonArray
:生成一个有效的 json 文档,而不是每行一个 json 对象 (文档)--pretty
:输出格式化的 json (docs)Mongo includes a mongoexport utility (see docs) which can dump a collection. This utility uses the native libmongoclient and is likely the fastest method.
Also helpful:
-o
: write the output to file, otherwise standard output is used (docs)--jsonArray
: generates a valid json document, instead of one json object per line (docs)--pretty
: outputs formatted json (docs)使用 mongoexport/mongoimport 转储/恢复集合:
导出 JSON 文件:
mongoexport --db; --collection <集合名称>; --out output.json
导入 JSON 文件:
mongoimport --db <数据库名称>; --collection <集合名称>; --文件输入.json
另外,http://bsonspec.org/
Use mongoexport/mongoimport to dump/restore a collection:
Export JSON File:
mongoexport --db <database-name> --collection <collection-name> --out output.json
Import JSON File:
mongoimport --db <database-name> --collection <collection-name> --file input.json
Also, http://bsonspec.org/
这是我的命令供参考:
在 Windows 7 (MongoDB 3.4) 上,必须将 cmd 移动到
mongod.exe
和mongo.exe
文件所在的位置 =>C:\MongoDB\Server\3.4\bin
否则它将无法工作,说它无法识别mongoexport
命令。Here's mine command for reference:
On Windows 7 (MongoDB 3.4), one has to move the cmd to the place where
mongod.exe
andmongo.exe
file resides =>C:\MongoDB\Server\3.4\bin
else it won't work saying it does not recongnizemongoexport
command.来自蒙戈文档:
在此处阅读更多信息:http: //www.mongodb.org/display/DOCS/mongoexport
From the Mongo documentation:
Read more here: http://www.mongodb.org/display/DOCS/mongoexport
这是我编写的一个小节点脚本,用于将特定数据库中的所有集合转储到指定的输出目录...
Here is a little node script that I write to dump all collections in a specific database to the specified output directory...