Navigation

Configure mongosh

The config API provides methods to examine and update the mongosh configuration. Updates made using config persist between sessions.

Note

The config API can be used within the mongosh command line interface. It has no effect in the embedded Compass shell.

Print the current mongosh configuration:

config

Return the current value for <property>:

config.get( "<property>" )

Change the current setting of <property> to <value>:

config.set( "<property>", <value> )
Key
Type
Default
Description
batchSize
integer
20
The number of items displayed per cursor iteration
enableTelemetry
boolean
true
Enables sending anonymized tracking and diagnostic data to MongoDB.
historyLength
integer
1000
The number of items to store in mongosh REPL's history file.
inspectDepth
integer or Infinity
6
The depth to which objects are printed. Setting inspectDepth to Infinity (the javascript object) prints all nested objects to their full depth.
showStackTraces
boolean
false
Controls display of a stack trace along with error messages.

Consider viewing a collection with a large number of documents. You can update the batchSize to limit the number of items returned by a cursor.

config.set("batchSize", 3)

Future db.collection.find() operations will only return 3 documents per cursor iteration.

Enable stack traces to see more detailed error reporting.

config.set("showStackTraces", true)

The output differs like this:

// showStackTraces set to 'false'
Enterprise> db.orders.find( {}, { $thisWontWork: 1 } )
MongoError: FieldPath field names may not start with '$'.
// showStackTraces set to 'true'
Enterprise> db.orders.find( {}, { $thisWontWork: 1 } )
Uncaught:
MongoError: FieldPath field names may not start with '$'.
at MessageStream.messageHandler (/usr/bin/mongosh:58878:20)
at MessageStream.emit (events.js:315:20)
at MessageStream.EventEmitter.emit (domain.js:548:15)
at processIncomingData (/usr/bin/mongosh:57954:12)
at MessageStream._write (/usr/bin/mongosh:57850:5)
at writeOrBuffer (_stream_writable.js:352:12)
at MessageStream.Writable.write (_stream_writable.js:303:10)
at Socket.ondata (_stream_readable.js:719:22)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:548:15)

You can call the config API from the command line using --eval with mongosh. In this case the --nodb option means mongosh will update without connecting to a MongoDB database.

Important

You must use different quotation marks for the --eval expression and the config property. That is, single quotes for one and double quotes for the other.

mongosh --nodb --eval 'config.set("enableTelemetry", true)'

mongosh returns additional information along with the result of the API call.

Current Mongosh Log ID: 609583b730e14918fa0d363f
Using MongoDB: undefined
Using Mongosh Beta: 0.12.1
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
Setting "enableTelemetry" has been changed
Give Feedback

On this page

  • Syntax
  • Examples