LinuxCommandLibrary

mongoexport

exports data from MongoDB collections to JSON or CSV files

TLDR

Export collection to JSON

$ mongoexport --db=[database] --collection=[collection] --out=[output.json]
copy
Export to CSV
$ mongoexport --db=[database] --collection=[collection] --type=csv --fields=[field1,field2] --out=[output.csv]
copy
Export with query filter
$ mongoexport --db=[database] --collection=[collection] --query='{"field":"value"}'
copy
Export from remote host
$ mongoexport --host=[hostname] --port=[27017] --db=[database] --collection=[collection]
copy

SYNOPSIS

mongoexport [options]

DESCRIPTION

mongoexport exports data from MongoDB collections to JSON or CSV files. Part of MongoDB Database Tools. Useful for backups, data migration, and reporting.

PARAMETERS

--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.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community