0

How can I create a mongodb procedure that can be scheduled to run once every day, at a fix time, say sharp at midnight GMT?

This google group link says you cannot schedule a task in mongoDB, they have a Jira for this, but you can use Window Task Scheduler which is described in this link. Is this the only way to achieve it? Is this a good way to do it?

Vivek Vardhan
  • 1,118
  • 3
  • 21
  • 44
  • http://stackoverflow.com/questions/16845707/backend-stored-procedure-schedulers-in-mongodb-database This also says use a `scripting language` to achieve it. So, I think I will need to use script to schedule the task in windows. Am i correct? – Vivek Vardhan Mar 23 '15 at 06:08
  • 1
    [As written in a different answer](http://stackoverflow.com/questions/24178128/why-mongodb-performance-better-on-linux-than-on-windows/24187943#24187943), running MongoDB on Windows is a bad idea for various reasons. Under Linux, you could use `crond` to run a `.js` file easily. If your requirement is to run MongoDB and have a reliable scheduler, the right tool for the job is Linux. – Markus W Mahlberg Mar 23 '15 at 09:39

2 Answers2

0

Quoting the comment by @Markus,

As written in a different answer, running MongoDB on Windows is a bad idea for various reasons. Under Linux, you could use crond to run a .js file easily. If your requirement is to run MongoDB and have a reliable scheduler, the right tool for the job is Linux.

This answer also mentions the way to solve this.

Community
  • 1
  • 1
Vivek Vardhan
  • 1,118
  • 3
  • 21
  • 44
0

This is done on Windows the same way you do on Linux.

ONE: Make a script in JavaScript to manage the task. This can be done in other languages if you prefer. This is a JavaScript script to rotate logs.

use admin
db.runCommand( { logRotate : 1 } )

TWO: Create a task in Task Scheduler to run the script. This can be done with the GUI, the API, or in XML. I usually set it up in the GUI and export the XML to allow parameterization of the database server, password, port, and user.

THREE: Include the execution of the script in the task

$MONGO_HOME/Mongo localhost:27017 -u myMongoServiceAccount -p somepassword LogRotate.js

The same concept can be applied to index management, gathering database stats, or managing stale locks.

Eric Aldinger
  • 125
  • 1
  • 6