Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Completed
Categories MongoDB Shell
Created by Guest
Created on Aug 6, 2020

Ability to execute a javascript file from inside the shell

Currently the only way to execute a javascript file from the mongo shell is to re-direct the input at shell login time (e.g. mongo --username ... < myscript.js). It would be helpful to have a way to execute the script from inside the shell via some sort of "run" command (e.g.from inside the shell "run /my/path/myscript.js".
  • ADMIN RESPONSE
    Oct 18, 2025
    Mongosh 0.10.0+ supports load() which seems to be exactly what you need. Please let me know if that is not what you had in mind.
  • Guest
    Apr 7, 2021
    Looks good to me.
  • Guest
    Oct 6, 2020
    In `mongo`, you can call `load('/my/path/myscript.js')` and we are planning to support the same or a similar API in `mongosh`. Is that close enough to what you are looking for?