|
| 1 | +.. _mongosh-shell-settings: |
| 2 | + |
| 3 | +===================== |
| 4 | +Configure ``mongosh`` |
| 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 | +:mongosh:`mongosh </>` configuration. Updates made using ``config`` |
| 16 | +persist between sessions. |
| 17 | + |
| 18 | +.. note:: |
| 19 | + |
| 20 | + The ``config`` API can be used within the ``mongosh`` command line |
| 21 | + interface. It has no effect in the |
| 22 | + :compass:`embedded Compass shell </embedded-shell>`. |
| 23 | + |
| 24 | +Syntax |
| 25 | +------ |
| 26 | + |
| 27 | +Print the current ``mongosh`` configuration: |
| 28 | + |
| 29 | +.. code-block:: javascript |
| 30 | + |
| 31 | + config |
| 32 | + |
| 33 | +Return the current value for ``<property>``: |
| 34 | + |
| 35 | +.. code-block:: javascript |
| 36 | + |
| 37 | + config.get( "<property>" ) |
| 38 | + |
| 39 | +Change the current setting of ``<property>`` to ``<value>``: |
| 40 | + |
| 41 | +.. code-block:: javascript |
| 42 | + |
| 43 | + config.set( "<property>", <value> ) |
| 44 | + |
| 45 | +Supported ``property`` parameters |
| 46 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 47 | + |
| 48 | +.. list-table:: |
| 49 | + :header-rows: 1 |
| 50 | + :widths: 25 15 10 50 |
| 51 | + |
| 52 | + * - Key |
| 53 | + - Type |
| 54 | + - Default |
| 55 | + - Description |
| 56 | + |
| 57 | + * - ``batchSize`` |
| 58 | + - integer |
| 59 | + - 20 |
| 60 | + - The number of items displayed per cursor iteration |
| 61 | + |
| 62 | + * - ``enableTelemetry`` |
| 63 | + - boolean |
| 64 | + - true |
| 65 | + - Enables sending anonymized tracking and diagnostic data to |
| 66 | + MongoDB. |
| 67 | + |
| 68 | + * - ``historyLength`` |
| 69 | + - integer |
| 70 | + - 1000 |
| 71 | + - The number of items to store in ``mongosh`` REPL's history file. |
| 72 | + |
| 73 | + * - ``inspectDepth`` |
| 74 | + - integer or Infinity |
| 75 | + - 6 |
| 76 | + - The depth to which objects are printed. Setting ``inspectDepth`` |
| 77 | + to ``Infinity`` (the javascript object) prints all nested |
| 78 | + objects to their full depth. |
| 79 | + |
| 80 | + * - ``showStackTraces`` |
| 81 | + - boolean |
| 82 | + - false |
| 83 | + - Controls display of a stack trace along with error messages. |
| 84 | + |
| 85 | + |
| 86 | +Examples |
| 87 | +-------- |
| 88 | + |
| 89 | +Update Number of Items Returned by a Cursor |
| 90 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 91 | + |
| 92 | +Consider viewing a collection with a large number of documents. You can |
| 93 | +update the ``batchSize`` to limit the number of items returned by a |
| 94 | +cursor. |
| 95 | + |
| 96 | +.. code-block:: javascript |
| 97 | + |
| 98 | + config.set("batchSize", 3) |
| 99 | + |
| 100 | + |
| 101 | +Future ``db.collection.find()`` operations will only return 3 documents |
| 102 | +per cursor iteration. |
| 103 | + |
| 104 | +Turn On Stack Traces |
| 105 | +~~~~~~~~~~~~~~~~~~~~ |
| 106 | + |
| 107 | +Enable stack traces to see more detailed error reporting. |
| 108 | + |
| 109 | +.. code-block:: javascript |
| 110 | + |
| 111 | + config.set("showStackTraces", true) |
| 112 | + |
| 113 | +The output differs like this: |
| 114 | + |
| 115 | +.. code-block:: javascript |
| 116 | + :copyable: false |
| 117 | + |
| 118 | + // showStackTraces set to 'false' |
| 119 | + Enterprise> db.orders.find( {}, { $thisWontWork: 1 } ) |
| 120 | + MongoError: FieldPath field names may not start with '$'. |
| 121 | + |
| 122 | + // showStackTraces set to 'true' |
| 123 | + Enterprise> db.orders.find( {}, { $thisWontWork: 1 } ) |
| 124 | + Uncaught: |
| 125 | + MongoError: FieldPath field names may not start with '$'. |
| 126 | + at MessageStream.messageHandler (/usr/bin/mongosh:58878:20) |
| 127 | + at MessageStream.emit (events.js:315:20) |
| 128 | + at MessageStream.EventEmitter.emit (domain.js:548:15) |
| 129 | + at processIncomingData (/usr/bin/mongosh:57954:12) |
| 130 | + at MessageStream._write (/usr/bin/mongosh:57850:5) |
| 131 | + at writeOrBuffer (_stream_writable.js:352:12) |
| 132 | + at MessageStream.Writable.write (_stream_writable.js:303:10) |
| 133 | + at Socket.ondata (_stream_readable.js:719:22) |
| 134 | + at Socket.emit (events.js:315:20) |
| 135 | + at Socket.EventEmitter.emit (domain.js:548:15) |
| 136 | + |
| 137 | +Call ``config`` API from outside the ``mongosh`` |
| 138 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 139 | + |
| 140 | +You can call the ``config`` API from the command line using |
| 141 | +:option:`--eval` with ``mongosh``. In this case the |
| 142 | +:option:`--nodb` option means ``mongosh`` will update without |
| 143 | +connecting to a MongoDB database. |
| 144 | + |
| 145 | +.. important:: |
| 146 | + |
| 147 | + You must use different quotation marks for the :option:`--eval` |
| 148 | + expression and the ``config`` property. That is, single quotes for |
| 149 | + one and double quotes for the other. |
| 150 | + |
| 151 | +.. code-block:: |
| 152 | + |
| 153 | + mongosh --nodb --eval 'config.set("enableTelemetry", true)' |
| 154 | + |
| 155 | +``mongosh`` returns additional information along with the result of the |
| 156 | +API call. |
| 157 | + |
| 158 | +.. code-block:: |
| 159 | + :copyable: false |
| 160 | + |
| 161 | + Current Mongosh Log ID: 609583b730e14918fa0d363f |
| 162 | + Using MongoDB: undefined |
| 163 | + Using Mongosh Beta: 0.12.1 |
| 164 | + |
| 165 | + For mongosh info see: https://docs.mongodb.com/mongodb-shell/ |
| 166 | + |
| 167 | + Setting "enableTelemetry" has been changed |
| 168 | + |
0 commit comments