Docs HomeMongoDB Shell

.mongoshrc Configuration File

On this page本页内容

On startup, mongosh checks your HOME directory for a JavaScript file named .mongoshrc.js. 启动时,mongosh会在HOME目录中检查一个名为.mongoshrc.js的JavaScript文件。If this file is found, mongosh reads the content of .mongoshrc.js before displaying the prompt for the first time.如果找到这个文件,mongosh会在第一次显示提示之前读取.mongoshrc.js的内容。

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. 如果您使用mongosh来评估JavaScript文件或表达式,无论是通过在命令行上使用--eval选项还是通过指定一个.js文件mongosh都会在JavaScript完成处理后读取.mongoshrc.jsYou can prevent .mongoshrc.js from being loaded by using the --norc option.您可以通过使用--norc选项来防止.mongoshrc.js被加载。

Note

The legacy mongo shell used a configuration file called .mongorc.js. 遗留的mongoshell使用了一个名为.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.如果mongosh在启动时检测到该文件,并且mongosrcjs不存在,则mongosh不会加载遗留的mongorcjs文件,并建议将mongorcjs重命名为mongohrcjs。

Example Usage示例用法

You can use the .mongoshrc file to customize mongosh startup behavior and add scripted functionality. 您可以使用.mongoshrc文件自定义mongosh启动行为并添加脚本功能。For examples, see Execute Code From a Configuration File.有关示例,请参阅从配置文件执行代码