问题描述
我正在使用mongoexport将一些数据导出到.json格式的文件中,但是该文档具有_id:IDVALUE元组引入的大量开销.
I am using mongoexport to export some data into .json formatted file, however the document has a large size overhead introduced by _id:IDVALUE tuples.
我找到了类似的帖子关于从mongo检索数据但不导出时如何省略_id字段的信息.建议使用:.Exclude("_id")
.我尝试重新查询mongoexport的--query参数,使其以某种方式包含.Exclude("_id")
参数,但是到目前为止,所有尝试均失败了.
I found a similar post Is there a way to retrieve data from MongoDB without the _id field? on how to omit the _id field when retrieving data from mongo, but not exporting. It is suggested to use: .Exclude("_id")
. I tried to reqrite the --query parameter of mongoexport to somehow include the .Exclude("_id")
parameter, but all of the attempts failed so far.
请建议执行此操作的正确方法是什么,还是应该恢复使用某些后期导出技术?
Please suggest what is the proper way of doing this, or should I revert to using some post-export techniques?
谢谢
推荐答案
似乎没有办法使用mongoexport排除字段(例如_id
).
There appears to be no way to exclude a field (such as _id
) using mongoexport.
以下是在中等大小的数据库上对我有用的替代方法:
Here's an alternative that has worked for me on moderate sized databases:
mongo myserver/mydb --quiet --eval "db.mycoll.find({}, {_id:0}).forEach(printjson);" > out.txt
在一个大型数据库(数百万个记录)上,可能需要一段时间,并且运行该数据库将影响人们尝试在系统上执行的其他操作:
On a large database (many millions of records) it can take a while and running this will affect other operations people try to do on the system:
这篇关于没有_id字段的mongoexport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!