mongoexport
Produce exports of data stored in a MongoDB instance formatted as JSON or CSV.
TLDR
Export a collection to stdout, formatted as JSON
$ mongoexport --uri=[connection_string] --collection=[collection_name]
Export the documents in the specified collection that match a query to a JSON file
$ mongoexport --db=[database_name] --collection=[collection_name] --query="[query_object]" --out=[path/to/file.json]
Export documents as a JSON array instead of one object per line
$ mongoexport --collection=[collection_name] --jsonArray
Export documents to a CSV file
$ mongoexport --collection=[collection_name] --type=[csv] --fields="[field1,field2,...]" --out=[path/to/file.csv]
Export documents that match the query in the specified file to a CSV file, omitting the list of field names on the first line
$ mongoexport --collection=[collection_name] --type=[csv] --fields="[field1,field2,...]" --queryFile=[path/to/file] --noHeaderLine --out=[path/to/file.csv]
Export documents to stdout, formatted as human-readable JSON
$ mongoexport --uri=[mongodb_uri] --collection=[collection_name] --pretty
Display help
$ mongoexport --help
SYNOPSIS
mongoexport [options]
DESCRIPTION
The mongoexport program allows exporting the contents of a running MongoDB instance to in CSV or JSON format.
OPTIONS
See mongoexport --help for a list supported options and their descriptions.
SEE ALSO
mongoimport(1) The full documentation of mongoexport can be found at https://docs.mongodb.com/manual/reference/program/mongoexport/.
AUTHOR
mongoexport was written by MongoDB, Inc. and is licensed under the Apache License, Version 2.0.
This manpage was written by Apollon Oikonomopoulos <apoikos@debian.org> for the Debian project (but may be used by others).