This version of the documentation is archived and no longer supported. To
upgrade your 5.0 deployment, see the MongoDB 6.0 upgrade procedures.
Note
The native method listed here is for the legacy mongo shell.
To use native methods in mongosh, see
Native Methods in mongosh.
Definition
load(file)Loads and runs a JavaScript file into the current shell environment.
The
load()method has the following parameter:ParameterTypeDescriptionfilenamestring
Specifies the path of a JavaScript file to execute.
Specify filenames with relative or absolute paths. When using relative path names, confirm the current directory using the
pwd()method.After executing a file with
load(), you may reference any functions or variables defined the file from withinmongosh.
Example
Consider the following examples of the load() method:
load("scripts/myjstest.js") load("/data/db/scripts/myjstest.js")