.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.js
。You can prevent .mongoshrc.js from being loaded by using the 您可以通过使用--norc
option.--norc
选项来防止.mongoshrc.js
被加载。
The legacy 遗留的mongo
shell used a configuration file called .mongorc.js. mongo
shell使用了一个名为.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.有关示例,请参阅从配置文件执行代码。