This version of the documentation is archived and no longer supported.


  • file (string) – Specify a path and file name containing JavaScript.

This native function loads and runs a JavaScript file into the current shell environment. To run JavaScript with the mongo shell, you can either:

  • use the “--eval” option when invoking the shell to evaluate a small amount of JavaScript code, or
  • specify a file name with “mongo”. mongo will execute the script and then exit. Add the --shell option to return to the shell after running the command.

Specify files loaded with the load() function in relative terms to the current directory of the mongo shell session. Check the current directory using the “pwd()” function.

←   listFiles() ls()  →