Docs Menu

Docs HomeMongoDB 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.

Note

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.

←  MethodsOptions →

On this page

Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.