Docs Menu

load()

On this page

  • Definition
  • Example
load(file)

Loads and runs a JavaScript file into the current shell environment.

The load() method has the following parameter:

Parameter
Type
Description
filename
string
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 within mongosh.

Consider the following examples of the load() method:

load("scripts/myjstest.js")
load("/data/db/scripts/myjstest.js")
←  listFiles()ls() →

On this page

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.