22 December,2020 by Rambler
Question: I have a js file - which iterates through some MongoDB collections - and currently I execute on an adhoc basis using the mongo shell. I now need to schedule this process on a regular basis and researching some effective methods to use? Can you supply some examples \ methods to deploy
Answer: I use two main methods to execute external js files . The first method utilises mongo shell & the second method use the MongoDB load function. Using this method gives you flexibility to trigger steps with a scheduler such as Crontab
Method 1 : Using the Mongo shell
mongo localhost:27017/mytest myjsfile.js
Method 2: Using the MongoDB load function
The load function supports absolute and relative file paths.
load("myjsfile.js")
--or
load("/mypath/myjsfile.js")
Read more MongoDB commands
Quick Access To Mongodb Commands Cheat Sheet
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |