I'm looking for a very simple way to export data from mongoDB into a CSV. Most of the answers involve bash scripts… etc. Is there a simple mongoDB command that will just export the data into CSV?
I'm looking for a very simple way to export data from mongoDB into a CSV. Most of the answers involve bash scripts… etc. Is there a simple mongoDB command that will just export the data into CSV?
Update:
从mongo 3.0.6开始,--csv
不再受支持,新的标志是--type=csv
,因此命令将是
mongoexport --db users --collection contacts --type=csv --fieldFile fields.txt
Original answer:
这可以使用mongo utility function mongoexport --csv
从命令行完成.
除了--csv
之外,文档还指出,您还需要使用--fields
或指定一个文件,其中包含using --fieldFile
中的字段.
看一看usage examples,看看它们是否有用,例如:
mongoexport --db users --collection contacts --csv --fieldFile fields.txt