且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何导出收集到csv在mongodb

更新时间:2022-12-31 10:41:39

@ karoly-horvath有没有错误。

@karoly-horvath has it right. Fields are required for csv.

根据MongoDB问题跟踪器中的此错误 https://jira.mongodb.org/browse/SERVER-4224 您必须在导出到csv 时提供字段。文档不清楚。这是错误的原因。

According to this bug in the MongoDB issue tracker https://jira.mongodb.org/browse/SERVER-4224 you MUST provide the fields when exporting to a csv. The docs are not clear on it. That is the reason for the error.

请尝试以下操作:

mongoexport --host localhost --db dbname --collection name --csv --out text.csv --fields firstName,middleName,lastName

UPDATE:

此提交:https://github.com/mongodb/mongo-tools/commit/586c00ef09c32c77907bd20d722049ed23065398 修复了3.0.0-rc10及更高版本的文档。

This commit: https://github.com/mongodb/mongo-tools/commit/586c00ef09c32c77907bd20d722049ed23065398 fixes the docs for 3.0.0-rc10 and later. It changes

Fields string `long:"fields" short:"f" description:"comma separated list of field names, e.g. -f name,age"`

Fields string `long:"fields" short:"f" description:"comma separated list of field names (required for exporting CSV) e.g. -f \"name,age\" "`