Skip to content

Commit 8d8e07c

Browse files
(DOCSP-20841): Global config file (#192)
* (DOCSP-20841): Global config file * refactor customize prompt page * standardize copy used in example * re-add reset syntax * updates per review * tweak * reformatting * move example higher up on page * Apply suggestions from code review Co-authored-by: Anna Henningsen <[email protected]> * formatting * alphabetize list * remove 'patterns' link Co-authored-by: Anna Henningsen <[email protected]>
1 parent de5d2b0 commit 8d8e07c

File tree

6 files changed

+523
-342
lines changed

6 files changed

+523
-342
lines changed

snooty.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ toc_landing_pages = ["/run-commands",
77
"/crud",
88
"/field-level-encryption",
99
"/write-scripts",
10-
"/snippets"
10+
"/snippets",
11+
"/reference/configure-shell-settings"
1112
]
1213

1314
[constants]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
.. list-table::
2+
:header-rows: 1
3+
:widths: 25 13 14 47
4+
5+
* - Key
6+
- Type
7+
- Default
8+
- Description
9+
10+
* - ``displayBatchSize``
11+
- integer
12+
- 20
13+
- The number of items displayed per cursor iteration
14+
15+
* - ``enableTelemetry``
16+
- boolean
17+
- true
18+
- Enables sending anonymized tracking and diagnostic data to
19+
MongoDB.
20+
21+
* - ``editor``
22+
- string
23+
- null
24+
- Designates an editor to use within the :binary:`~bin.mongosh`
25+
console. Overrides the ``EDITOR`` environment variable if set.
26+
27+
* - ``historyLength``
28+
- integer
29+
- 1000
30+
- The number of items to store in :binary:`~bin.mongosh` REPL's
31+
history file.
32+
33+
* - ``inspectCompact``
34+
- integer or boolean
35+
- 3
36+
- The level of inner elements that :binary:`~bin.mongosh` outputs
37+
on a single line. Short array elements are also grouped together
38+
on a single line.
39+
40+
If set to ``false``, :binary:`~bin.mongosh` outputs each field
41+
on its own line.
42+
43+
* - ``inspectDepth``
44+
- integer or Infinity
45+
- 6
46+
- The depth to which objects are printed. Setting ``inspectDepth``
47+
to ``Infinity`` (the javascript object) prints all nested
48+
objects to their full depth.
49+
50+
* - ``redactHistory``
51+
- string
52+
- ``remove``
53+
- Controls what information is recorded in the shell history.
54+
Must be one of:
55+
56+
- ``keep``: Retain all history.
57+
- ``remove``: Remove lines which contain sensitive information.
58+
- ``remove-redact``: Redact sensitive information.
59+
60+
* - ``showStackTraces``
61+
- boolean
62+
- false
63+
- Controls display of a stack trace along with error messages.
64+
65+
* - ``snippetAutoload``
66+
- boolean
67+
- true
68+
- If ``true``, automatically load installed
69+
:ref:`snippets <snip-overview>` at startup.
70+
71+
* - ``snippetIndexSourceURLs``
72+
- string
73+
- `MongoDB Repository
74+
<https://compass.mongodb.com/mongosh/snippets-index.bson.br>`__
75+
- A semicolon-separated list of URLs that link to a
76+
:ref:`snippet <snip-overview>` registry.
77+
78+
* - ``snippetRegistryURL``
79+
- string
80+
- `npm Registry <https://registry.npmjs.org>`__
81+
- The npm registry used by the :binary:`~bin.mongosh` npm client
82+
that installs :ref:`snippet <snip-overview>`.
Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
.. _configure-settings-api:
2+
3+
==============================================
4+
Configure :binary:`~bin.mongosh` Using the API
5+
==============================================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
14+
The ``config`` API provides methods to examine and update the
15+
:binary:`~bin.mongosh` configuration. Updates made using the ``config``
16+
API persist between sessions.
17+
18+
.. note::
19+
20+
The ``config`` API can be used within the :binary:`~bin.mongosh`
21+
command line interface. It has no effect in the
22+
:compass:`embedded Compass shell </embedded-shell>`.
23+
24+
Syntax
25+
------
26+
27+
Print the current :binary:`~bin.mongosh` configuration:
28+
29+
.. _mongosh-config:
30+
31+
.. code-block:: javascript
32+
33+
config
34+
35+
Return the current value for ``<property>``:
36+
37+
.. code-block:: javascript
38+
39+
config.get( "<property>" )
40+
41+
.. _mongosh-config-set:
42+
43+
Change the current setting of ``<property>`` to ``<value>``:
44+
45+
.. code-block:: javascript
46+
47+
config.set( "<property>", <value> )
48+
49+
Reset a ``<property>`` to the default value:
50+
51+
.. code-block:: javascript
52+
53+
config.reset( "<property>" )
54+
55+
Supported ``property`` parameters
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
58+
.. include:: /includes/list-table-shell-properties.rst
59+
60+
Behavior
61+
--------
62+
63+
Remove or Redact Sensitive Information From History
64+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65+
66+
:binary:`~bin.mongosh` makes "best-effort" attempts to match patterns
67+
that normally correspond to certain kinds of sensitive information.
68+
69+
There are patterns that match:
70+
71+
- Certificates and keys
72+
- Email addresses
73+
- Generic user directories
74+
- HTTP(s) URLs
75+
- IP addresses
76+
- MongoDB connection strings
77+
78+
Certain operations, such as :method:`connect()`, are considered
79+
inherently sensitive. If ``redactHistory`` is set to ``remove`` or
80+
``remove-redact``, lines with these operations will be removed from the
81+
:ref:`command line history <mdb-shell-command-history>`.
82+
83+
Other operations, like :method:`~db.collection.find()`, sometimes have
84+
sensitive information like email addresses. The
85+
:ref:`shell history <mdb-shell-command-history>` will retain these
86+
lines as entered unless ``redactHistory`` is set to ``remove-redact``.
87+
88+
Behavior with Configuration File
89+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90+
91+
Settings specified with the ``config`` API:
92+
93+
- Override settings specified in the :ref:`configuration file
94+
<configure-settings-global>`.
95+
96+
- Persist across restarts.
97+
98+
.. example::
99+
100+
Consider the following configuration file that sets the
101+
``inspectDepth`` setting to ``20``:
102+
103+
.. code-block:: yaml
104+
105+
mongosh:
106+
inspectDepth: 20
107+
108+
During your ``mongosh`` session you run the following command to set
109+
``inspectDepth`` to ``10``:
110+
111+
.. code-block:: javascript
112+
113+
config.set( "inspectDepth": 10 )
114+
115+
The value of ``inspectDepth`` becomes ``10``, and will remain ``10``
116+
even when ``mongosh`` is restarted.
117+
118+
Examples
119+
--------
120+
121+
Update Number of Items Returned by a Cursor
122+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123+
124+
Consider viewing a collection with a number of large documents. You can
125+
update the ``batchSize`` to limit the number of items returned by a
126+
cursor.
127+
128+
.. code-block:: javascript
129+
130+
config.set("displayBatchSize", 3)
131+
132+
133+
Future ``db.collection.find()`` operations will only return 3 documents
134+
per cursor iteration.
135+
136+
Turn On Stack Traces
137+
~~~~~~~~~~~~~~~~~~~~
138+
139+
Enable stack traces to see more detailed error reporting.
140+
141+
.. code-block:: javascript
142+
143+
config.set("showStackTraces", true)
144+
145+
The output differs like this:
146+
147+
.. code-block:: javascript
148+
:copyable: false
149+
150+
// showStackTraces set to 'false'
151+
Enterprise> db.orders.find( {}, { $thisWontWork: 1 } )
152+
MongoError: FieldPath field names may not start with '$'.
153+
154+
// showStackTraces set to 'true'
155+
Enterprise> db.orders.find( {}, { $thisWontWork: 1 } )
156+
Uncaught:
157+
MongoError: FieldPath field names may not start with '$'.
158+
at MessageStream.messageHandler (/usr/bin/mongosh:58878:20)
159+
at MessageStream.emit (events.js:315:20)
160+
at MessageStream.EventEmitter.emit (domain.js:548:15)
161+
at processIncomingData (/usr/bin/mongosh:57954:12)
162+
at MessageStream._write (/usr/bin/mongosh:57850:5)
163+
at writeOrBuffer (_stream_writable.js:352:12)
164+
at MessageStream.Writable.write (_stream_writable.js:303:10)
165+
at Socket.ondata (_stream_readable.js:719:22)
166+
at Socket.emit (events.js:315:20)
167+
at Socket.EventEmitter.emit (domain.js:548:15)
168+
169+
Call ``config`` API from outside :binary:`~bin.mongosh`
170+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171+
172+
You can call the ``config`` API from the command line using
173+
:option:`--eval` with :binary:`~bin.mongosh`. In this case the
174+
:option:`--nodb` option means :binary:`~bin.mongosh` will update
175+
without connecting to a MongoDB database.
176+
177+
.. important::
178+
179+
You must use different quotation marks for the :option:`--eval`
180+
expression and the ``config`` property. That is, single quotes for
181+
one and double quotes for the other.
182+
183+
.. code-block::
184+
185+
mongosh --nodb --eval 'config.set("enableTelemetry", true)'
186+
187+
:binary:`~bin.mongosh` returns additional information along with the
188+
result of the API call.
189+
190+
.. code-block::
191+
:copyable: false
192+
193+
Current Mongosh Log ID: 609583b730e14918fa0d363f
194+
Using MongoDB: undefined
195+
Using Mongosh Beta: 0.12.1
196+
197+
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
198+
199+
Setting "enableTelemetry" has been changed
200+
201+
Redact Sensitive Information
202+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203+
204+
Compare the recalled history when ``redactHistory`` is set to
205+
``remove-redact`` or ``remove``.
206+
207+
Set ``redactHistory`` to ``remove-redact`` mode and enter a query
208+
containing an email address.
209+
210+
.. code-block:: javascript
211+
212+
config.set( "redactHistory", "remove-redact" )
213+
db.contacts.find( {"email": "[email protected]" } )
214+
215+
When you press the ``up arrow`` to replay the last command the email
216+
address is redacted.
217+
218+
.. code-block:: javascript
219+
:copyable: false
220+
221+
db.contacts.find( {"email": "<email>" } ) // Redacted
222+
223+
Set ``redactHistory`` to ``remove`` mode and enter a query containing
224+
an email address.
225+
226+
.. code-block:: javascript
227+
228+
config.set( "redactHistory", "remove" )
229+
db.contacts.find( {"email": "[email protected]" } )
230+
231+
When you press the ``up arrow`` to replay the last command the email
232+
address is present.
233+
234+
.. code-block:: javascript
235+
:copyable: false
236+
237+
db.contacts.find( {"email": "[email protected]" } )
238+
239+
The :ref:`shell history <mdb-shell-command-history>` reflects the
240+
changes. (Note that this stores the most recent input first.)
241+
242+
.. code-block:: javascript
243+
:copyable: false
244+
245+
db.contacts.find( {"email": "[email protected]" } )
246+
config.set( "redactHistory", "remove" )
247+
db.contacts.find( {"email": "<email>" } )
248+
config.set( "redactHistory", "remove-redact" )
249+
250+
.. _example-reset-setting:
251+
252+
Reset a Configuration Setting to the Default Value
253+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254+
255+
If you modified a configuration setting and want to reset it to the
256+
default value, use ``config.reset( "<property>" )``.
257+
258+
#. Change the value of the ``historyLength`` setting to ``2000``:
259+
260+
.. code-block:: javascript
261+
262+
config.set("historyLength", 2000)
263+
264+
#. Verify the updated value for ``historyLength``:
265+
266+
.. code-block:: javascript
267+
268+
config.get("historyLength")
269+
270+
#. Reset the ``historyLength`` setting to the default value of ``1000``:
271+
272+
.. code-block:: javascript
273+
274+
config.reset("historyLength")
275+
276+
#. Verify the updated value for ``historyLength``:
277+
278+
.. code-block:: javascript
279+
280+
config.get("historyLength")

0 commit comments

Comments
 (0)