File tree Expand file tree Collapse file tree 4 files changed +30
-17
lines changed Expand file tree Collapse file tree 4 files changed +30
-17
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
1
+ To get output suitable for automated parsing, use
2
+ ``EJSON.stringify() ``.
3
+
1
4
.. code-block :: javascript
2
5
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
7
10
8
11
After parsing with ``jq ``, the output resembles this:
9
12
Original file line number Diff line number Diff line change @@ -165,8 +165,7 @@ in ``mongosh`` better align with the types used by the MongoDB Drivers.
165
165
``--eval`` Behavior
166
166
-------------------
167
167
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.
170
169
171
170
.. include:: /includes/examples/ex-eval-output.rst
172
171
Original file line number Diff line number Diff line change @@ -25,19 +25,22 @@ General Options
25
25
26
26
.. option:: --eval <javascript>
27
27
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`` .
35
35
36
- To get output suitable for automated parsing, use
37
- ``EJSON.stringify()``.
36
+ **Example: Format Output**
38
37
39
38
.. include:: /includes/examples/ex-eval-output.rst
40
39
40
+ **Example: Multiple ``--eval`` Arguments**
41
+
42
+ .. include:: /includes/examples/ex-eval-multi.rst
43
+
41
44
.. option:: --help, -h
42
45
43
46
Returns information on the options and use of the |mdb-shell|.
@@ -445,8 +448,6 @@ Authentication Options
445
448
:option:`--password <--password>` and
446
449
:option:`--authenticationDatabase <--authenticationDatabase>`
447
450
options.
448
-
449
-
450
451
451
452
Session Options
452
453
---------------
You can’t perform that action at this time.
0 commit comments