Skip to content

Commit 21e09ee

Browse files
author
Dave Cuthbert
authored
DOCSP-23367 multiple eval args (#229)
* DOCSP-23367 multiple eval arguments * DOCSP-23367 multiple eval arguments * DOCSP-23367 multiple eval arguments * DOCSP-23367 multiple eval arguments * DOCSP-23367 multiple eval arguments
1 parent 460e16e commit 21e09ee

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
To get a list of collections in the ``moviesDatabase``, use multiple
2+
``--eval`` statements:
3+
4+
.. code-block:: javascript
5+
6+
mongosh --quiet \
7+
--eval 'use moviesDatabase' \
8+
--eval 'show collections' \
9+
mongodb://localhost/
10+

source/includes/examples/ex-eval-output.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
To get output suitable for automated parsing, use
2+
``EJSON.stringify()``.
3+
14
.. code-block:: javascript
25
3-
mongosh --quiet --host rs0/centos1104 --port 27500 \
4-
--eval "EJSON.stringify(rs.status().members.map( \
5-
m => ({'id':m._id, 'name':m.name, 'stateStr':m.stateStr})));" \
6-
| jq
6+
mongosh --quiet --host rs0/centos1104 --port 27500 \
7+
--eval "EJSON.stringify(rs.status().members.map( \
8+
m => ({'id':m._id, 'name':m.name, 'stateStr':m.stateStr})));" \
9+
| jq
710
811
After parsing with ``jq``, the output resembles this:
912

source/reference/compatibility.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ in ``mongosh`` better align with the types used by the MongoDB Drivers.
165165
``--eval`` Behavior
166166
-------------------
167167

168-
``mongosh --eval`` does not quote object keys in its ouptut. To get
169-
output suitable for automated parsing, use ``EJSON.stringify()``.
168+
``mongosh --eval`` does not quote object keys in its ouptut.
170169

171170
.. include:: /includes/examples/ex-eval-output.rst
172171

source/reference/options.txt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ General Options
2525

2626
.. option:: --eval <javascript>
2727

28-
Evaluates a JavaScript expression that is specified as an argument.
29-
``mongosh`` does not load its own environment when evaluating
30-
code. As a result many options of the shell environment are not
31-
available.
32-
33-
The result of evaluating a JavaScript argument is printed to your
34-
command line.
28+
Evaluates a JavaScript expression. You can use a single ``--eval``
29+
argument or multiple ``--eval`` arguments together.
30+
31+
After ``mongosh`` evaluates the ``--eval`` argument, it prints the
32+
results to your command line. If you use multiple ``--eval``
33+
statements, ``mongosh`` only prints the results of the last
34+
``--eval``.
3535

36-
To get output suitable for automated parsing, use
37-
``EJSON.stringify()``.
36+
**Example: Format Output**
3837

3938
.. include:: /includes/examples/ex-eval-output.rst
4039

40+
**Example: Multiple ``--eval`` Arguments**
41+
42+
.. include:: /includes/examples/ex-eval-multi.rst
43+
4144
.. option:: --help, -h
4245

4346
Returns information on the options and use of the |mdb-shell|.
@@ -445,8 +448,6 @@ Authentication Options
445448
:option:`--password <--password>` and
446449
:option:`--authenticationDatabase <--authenticationDatabase>`
447450
options.
448-
449-
450451

451452
Session Options
452453
---------------

0 commit comments

Comments
 (0)