Run JS Script on MongoDB StartUp

361 views
Skip to first unread message

Cindy Conway

unread,
Oct 27, 2014, 8:11:59 PM10/27/14
to mongod...@googlegroups.com
Hello All,

I have scoured the interwebs, and I cannot find a way to run a js script right after Mongo starts. I need to automatically check a value on restarting the mongod service. Any suggestions? 

Many mahalos,
Cindy

Stephen Steneker

unread,
Oct 27, 2014, 11:38:15 PM10/27/14
to mongod...@googlegroups.com
On Tuesday, 28 October 2014 11:11:59 UTC+11, Cindy Conway wrote:
I have scoured the interwebs, and I cannot find a way to run a js script right after Mongo starts. I need to automatically check a value on restarting the mongod service. Any suggestions? 

Hi Cindy,

There isn't a server feature to run JavaScript on mongod startup.

One suggestion would be to write a bash shell wrapper to start/restart the mongod service and run your JavaScript code afterward.

Alternatively you could write an app which periodically pings the server and checks the uptime to infer a restart since the last check (eg. value of "db.serverStatus().uptime" in the shell).

What sort of value do you need to check?

Regards,
Stephen

Cindy Conway

unread,
Oct 28, 2014, 12:24:29 PM10/28/14
to mongod...@googlegroups.com
I am using the oplog and a js script to do a role-your-own version of transaction handling. Basically on certain events, I need to move documents between collections. I am accomplishing this by putting the some information in a transaction collection, then when the oplog registers a change to this collection, a js script runs that make the changes to the documents. It also tracks where it is in the process, so if there is a failure, it will pick up where it left off and complete the transaction. However, it is only triggered when the oplog registers a change. This means that if the server crashes, the transaction processing will not pick up again until the first time after the crash that the transaction collection is changed. This could potentialy leave half completed transactions dangling.
Reply all
Reply to author
Forward
0 new messages