Skip to content

Commit 967c156

Browse files
DOCSP-25081 Document --json flag for the mongosh CLI (#322)
* DOCSP-25081 Document --json flag for the mongosh CLI * Update source/includes/examples/ex-eval-json.rst Co-authored-by: Anna Henningsen <[email protected]> * DOCSP-25081 updates for NV's feedback --------- Co-authored-by: Anna Henningsen <[email protected]>
1 parent c549e8b commit 967c156

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
To return statistics about a collection in Extended JSON format using
2+
multiple ``--eval`` statements:
3+
4+
.. code-block:: sh
5+
6+
mongosh --quiet --json=relaxed \
7+
--eval 'use <database-name>' \
8+
--eval 'db.<collection>.stats()' \
9+
mongodb://localhost/

source/reference/options.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,25 @@ General Options
3737
statements, ``mongosh`` only prints the results of the last
3838
``--eval``.
3939

40+
You can use the ``--json`` flag with ``--eval`` to return
41+
``mongosh`` results in :manual:`Extended JSON
42+
</reference/mongodb-extended-json/>` format. ``mongosh``
43+
supports both ``--json=canonical`` and ``--json=relaxed`` modes. If
44+
you omit the mode, ``mongosh`` defaults to the ``canonical``
45+
mode. The ``--json`` flag is mutually exclusive with ``--shell``.
46+
4047
**Example: Format Output**
4148

4249
.. include:: /includes/examples/ex-eval-output.rst
4350

44-
**Example: Multiple ``--eval`` Arguments**
51+
**Example: Multiple --eval Arguments**
4552

4653
.. include:: /includes/examples/ex-eval-multi.rst
4754

55+
**Example: --json Option**
56+
57+
.. include:: /includes/examples/ex-eval-json.rst
58+
4859
.. option:: --file, -f <javascript>
4960

5061
Runs a script from the command line without entering the
@@ -77,7 +88,8 @@ General Options
7788
command and specify a JavaScript file as an argument, or use
7889
:option:`--eval <--eval>` to specify JavaScript on the command line,
7990
the :option:`--shell <--shell>` option provides the user with a shell
80-
prompt after the file finishes executing.
91+
prompt after the file finishes executing. The ``--shell`` flag is
92+
mutually exclusive with ``--json``.
8193

8294
.. option:: --verbose
8395

0 commit comments

Comments
 (0)