Skip to content

DOCS-1228 mongoexport:clarify that --csv requires fields to be specified #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions source/reference/mongoexport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ Options

.. option:: --fieldFile <file>

As an alternative to ":option:`--fields <mongoexport --fields>`"
As an alternative to :option:`--fields <mongoexport --fields>`,
the :option:`--fieldFile` option allows you to specify a file
(e.g. ``<file>```) to hold a list of field names to specify a list
(e.g. ``<file>``) to hold a list of field names to specify a list
of fields to *include* in the export. All other fields will be
*excluded* from the export. Place one field per line.
Lines must end with the LF character (``0x0A``).

.. option:: --query <JSON>

Expand All @@ -157,6 +158,10 @@ Options
format. By default :program:`mongoexport` writes data using one
:term:`JSON` document for every MongoDB document.

If you specify :option:`--csv`, then you must specify either
the :option:`--fieldFile` option or :option:`--fields` option to
describe which fields to export from the collection.

.. option:: --jsonArray

Modifies the output of :program:`mongoexport` to write the
Expand Down Expand Up @@ -211,10 +216,11 @@ collection ``contacts`` from the ``users`` database from the
:program:`mongod` instance running on the localhost port
number ``27017``. This command writes the export data in :term:`CSV`
format into a file located at ``/opt/backups/contacts.csv``.
The :file:`fields.txt` file contains a line-by-line list of fields to export.

.. code-block:: sh

mongoexport --db users --collection contacts --csv --out /opt/backups/contacts.csv
mongoexport --db users --collection contacts --csv --fieldFile fields.txt --out /opt/backups/contacts.csv

The next example creates an export of the collection ``contacts``
from the MongoDB instance running on the localhost port number ``27017``,
Expand Down