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.mongosh会检查HOME目录中是否有一个名为.mongoshrc.js的JavaScript文件。如果找到此文件,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.js。You can prevent .mongoshrc.js from being loaded by using the 您可以通过使用--norc option.--norc选项来阻止.mongoshrc.js被加载。
Note
Legacy Shell Configuration旧Shell配置
The legacy 传统的mongo shell uses a configuration file named .mongorc.js.mongoshell使用一个名为.mongorc.js的配置文件。
If 如果mongosh finds .mongorc.js on startup but doesn't find .mongoshrc.js, mongosh doesn't load the legacy .mongorc.js file and states you should rename .mongorc.js to .mongoshrc.js.mongosh在启动时找到.mongorc.js,但找不到.mongoshrc.js,mongosh不会加载遗留的.mongorc.js文件,并建议您将.mongorc.js重命名为.mongoshrc.js。
Example Usage示例用法
You can use the .mongoshrc file to customize 您可以使用.mongoshrc文件自定义mongosh startup behavior and add scripted functionality. For examples, see Execute Code From a Configuration File.mongosh启动行为并添加脚本功能。有关示例,请参阅从配置文件执行代码。