This is a bit omitted in previous articles about using mongodb shell to execute scripts. Now I will add a supplement to this blog. I. Input a script file in the command line to define a javasciprt file, name: script1.js, content: print (iamalbert tshaointhescript1.js) defines another javascript file, name
This is a bit omitted in previous articles about using mongodb shell to execute scripts. Now I will add a supplement to this blog. I. Input a script file in the command line to define a javasciprt file, name: script1.js, content: print (I am albert shao in the script1.js) defines another javascript file, name
The use of mongodb shell to execute scripts is a bit omitted in previous articles; now I will add a supplement to this blog;
1. input the script file in the command line
Define a javasrt RT file named script1.js with the following content:
print("I am albert shao in the script1.js")
Define another javascript file named script2 with the following content:
print("I like to read and study")
Run the following command in the Command window:
Note: The script file must be stored in the same directory of mongo. <喎?http: www.2cto.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + yOe5 + 8 + fingerprint + rrNtsu/fingerprint + tcTD + 7PGo7s8L3A + fingerprint + PC9wPgo8aDI + fingerprint + pc9omj4kpgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20141119/2014111909274934.png" alt = "\">
3. Create a. mongorc. js File
If some scripts are frequently loaded, you can add them to the mongor. js file. This file will automatically run when the shell is started;
For example, we want to start shell to display a welcome statement. In the user's home directory, create a file named [. mongorc. js] and add the following code to it:
var compliment = ["like albert","attractive","intellgient"];var index = Math.floor(Math.random()*3);print("Hello, you're looking particularly " + compliment[index] + " today!");
It is expected that the file directory will be automatically loaded directly:
Run:
If the directory is not in the administer directory, You need to specify it as follows: