![MongoDB 4 Quick Start Guide](https://wfqqreader-1252317822.image.myqcloud.com/cover/381/36699381/b_36699381.jpg)
上QQ阅读APP看书,第一时间看更新
.mongorc.js File
All command line option flags can be coded into a file, mongorc.js (https://docs.mongodb.com/manual/reference/program/mongo/#files). When you run the mongo command, this file is parsed unless you include the command line switch mongo --norc. There are two primary locations for this file; the user home directory, or the operating system's /etc directory:
![](https://epubservercos.yuewen.com/845C96/19470388008854906/epubprivate/OEBPS/Images/95d0d761-f613-4d33-be48-044d7eaa5801.png?sign=1739317163-9gpJj3Q2DNCCD3gwTsHWOLT5p1DROCwT-0-dc8923f602764ad8bbec8ae3cff4ee16)
It is very important to set the rights properly if using /etc/mongorc.js. Otherwise, you will receive a permissions error when the mongo shell first starts. The recommended rights would be to assign ownership to the user mongodb, and read + execute rights to all others.
Here is a sample mongorc.js file, which customizes the prompt (https://docs.mongodb.com/manual/tutorial/configure-mongo-shell/) to display the database, hostname, and up time:
![](https://epubservercos.yuewen.com/845C96/19470388008854906/epubprivate/OEBPS/Images/76927288-b14d-4260-b960-a52c77d3de37.png?sign=1739317163-FMoYBqGM2roF6B52mLPcTleumMIwdZz7-0-e1f419be628876e80376cabb024c3604)
If you have defined both a global /etc/mongorc.js as well as a ~/.mongorc.js config file in the user home folder, the global file will be processed first. Another important consideration is that if the user uses the --norc option, it only suppresses execution of the local home directory file, not the global mongorc.js file.