Skip to content

DOCS-10945: adds --noHeaderLine option to mongoexport #3163

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
Closed
Show file tree
Hide file tree
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
24 changes: 22 additions & 2 deletions source/includes/options-mongoexport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ description: |
specified field(s) is a field within a sub-document, the
:binary:`~bin.mongoexport` includes the sub-document with all
its fields, not just the specified field within the document.

See: :ref:`mongoexport-fields-example` for sample usage.
optional: true
---
program: mongoexport
Expand All @@ -207,6 +209,8 @@ description: |

:binary:`~bin.mongoexport` includes only the specified field(s). The
specified field(s) can be a field within a sub-document.

See :ref:`mongoexport-fieldFile-example` for sample usage.
optional: true
---
program: mongoexport
Expand Down Expand Up @@ -257,7 +261,7 @@ directive: option
args: <string>
description: |

.. versionadded:: 3.0.0
.. versionadded:: 3.0

Specifies the file type to export. Specify ``csv`` for :term:`CSV`
format or ``json`` for :term:`JSON` format.
Expand Down Expand Up @@ -398,4 +402,20 @@ description: |
Otherwise, {{program}} defaults to :readmode:`nearest`.

.. include:: /includes/warning-read-preference-mongos.rst
...
---
program: mongoexport
directive: option
optional: true
name: noHeaderLine
args: null
description: |
.. versionadded:: 3.4

By default, {{program}} includes the exported field names as the first
line in a CSV output. {{role}} directs {{program}} to export the
data without the list of field names.
{{role}} is **only valid** with the
:option:`--type <mongoexport --type>` option with value ``csv``.

See :ref:`mongoexport-noHeaderLine-example` for sample usage.
...
47 changes: 44 additions & 3 deletions source/reference/program/mongoexport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ Options

.. include:: /includes/option/option-mongoexport-pretty.rst

.. include:: /includes/option/option-mongoexport-noHeaderLine.rst

.. include:: /includes/option/option-mongoexport-slaveOk.rst

.. include:: /includes/option/option-mongoexport-readPreference.rst
Expand All @@ -158,6 +160,11 @@ Export in CSV Format

.. include:: /includes/fact-3.0-mongoexport-drop-csv-option.rst

.. _mongoexport-fields-example:

Export Data in CSV Format using ``--fields`` option
```````````````````````````````````````````````````

In the following example, :binary:`~bin.mongoexport` exports data from the
collection ``contacts`` collection in the ``users`` database in :term:`CSV`
format to the file ``/opt/backups/contacts.csv``.
Expand All @@ -173,6 +180,19 @@ to export.

mongoexport --db users --collection contacts --type=csv --fields name,address --out /opt/backups/contacts.csv

The output would then resemble:

.. code-block:: csv

name, address
Sophie Monroe, 123 Example Road
Charles Yu, 345 Sample Street

.. _mongoexport-fieldFile-example:

Use a File to Specify the Fields to Export in CSV Format
````````````````````````````````````````````````````````

For CSV exports only, you can also specify the fields in a file
containing the line-separated list of fields to export. The file must
have only one field per line.
Expand All @@ -192,9 +212,30 @@ the file:

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

.. versionchanged:: 3.0.0
:binary:`~bin.mongoexport` removed the ``--csv`` option and replaced with
the :option:`--type <mongoexport --type>` option.
.. _mongoexport-noHeaderLine-example:

Exclude Field Names from CSV Output
```````````````````````````````````

.. versionadded:: 3.4

MongoDB 3.4 added the :option:`--noHeaderLine <mongoexport --noHeaderLine>` option for excluding the
field names in a CSV export. The following example exports the ``name``
and ``address`` fields in the ``contacts`` collection in the ``users``
database and uses :option:`--noHeaderLine <mongoexport --noHeaderLine>` to suppress the output
of the field names as the first line:

.. code-block:: sh

mongoexport --db users --collection contacts --type csv --fields name,address --noHeaderLine --out /opt/backups/contacts.csv

The CSV output would then resemble:

.. code-block:: csv

Sophie Monroe, 123 Example Road
Charles Yu, 345 Sample Street


Export in JSON Format
~~~~~~~~~~~~~~~~~~~~~
Expand Down