Linux command
mongoexport 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Export collection to JSON
mongoexport --db=[database] --collection=[collection] --out=[output.json]
Export to CSV
mongoexport --db=[database] --collection=[collection] --type=csv --fields=[field1,field2] --out=[output.csv]
Export with query filter
mongoexport --db=[database] --collection=[collection] --query='{"field":"value"}'
Export from remote host
mongoexport --host=[hostname] --port=[27017] --db=[database] --collection=[collection]
说明
mongoexport exports data from MongoDB collections to JSON or CSV files. Part of MongoDB Database Tools. Useful for backups, data migration, and reporting.
参数
- --db _name_
- Database name.
- --collection _name_
- Collection to export.
- --out _file_
- Output file path.
- --type _type_
- Output type (json, csv).
- --fields _fields_
- Fields for CSV export.
- --query _json_
- Filter query.
- --host _host_
- MongoDB host.
FAQ
What is the mongoexport command used for?
mongoexport exports data from MongoDB collections to JSON or CSV files. Part of MongoDB Database Tools. Useful for backups, data migration, and reporting.
How do I run a basic mongoexport example?
Run `mongoexport --db=[database] --collection=[collection] --out=[output.json]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --db _name_ do in mongoexport?
Database name.