Docs Menu
Docs Home
MongoDB Shell

.mongoshrc Configuration File

On this page

  • Example Usage

On startup, mongosh checks your HOME directory for a JavaScript file named .mongoshrc.js. If this file is found, mongosh reads the content of .mongoshrc.js before displaying the prompt for the first time.

If you use mongosh to evaluate a JavaScript file or expression, either by using the --eval option on the command line or by specifying a .js file, mongosh reads .mongoshrc.js after the JavaScript has finished processing. You can prevent .mongoshrc.js from being loaded by using the --norc option.


Legacy Shell Configuration

The legacy mongo shell used a configuration file called .mongorc.js. If mongosh detects this file on startup and .mongoshrc.js is not present, mongosh does not load the legacy .mongorc.js file, and suggests renaming .mongorc.js to .mongoshrc.js.

You can use the .mongoshrc file to customize mongosh startup behavior and add scripted functionality. For examples, see Execute Code From a Configuration File.





On this page