Write and run custom scripts for your mongoDB using nodeJS.
$ git clone https://github.com/ifatoki/mongo_scripts
$ cd mongo_scripts
$ npm install
-
Create a copy of the .env.sample file in the project and name it .env.
-
Replace the default
MONGO_URI
with the mongo server you want to connect to. -
Replace the default
DB_NAME
with the name of the DB you would like to run the script on.
-
Replace the value in the
SCRIPT_NAME
field in the .env file with the filename of the script (already existing in the custom_scripts folder). -
Run
npm run start
-
In the custom_scripts dir, copy the file script_template.js and create a copy of it, naming it as you wish (note, this name is what you'd use to reference it in the .env file).
-
Write your script logic below the line
// Write your script here
-
When done, run it as directed above in the Running a script section