JS Scripts
Running JS Scripts on MongoDB
Updated: 23 December 2025
More information here
JavaScript can be used to manipulate a MongoDB Database from within the mongo shell. To do this you can make use of the mongo shell
Create a Script
To create a script, you simply need to create a .js file, the db object will be the current database (set when running the script) and pretty much holds the database reference
Note that
console.log
MyDbScript.js
1print(db)Run a Script
To run the script, you will do the following from the terminal:
1mongo DBName MyDbScript.js// To update with more detailed examples