Job Schedule in Mongodb

4,447 views
Skip to first unread message

Tom Vo

unread,
Oct 2, 2012, 10:43:52 PM10/2/12
to mongod...@googlegroups.com
Dear all
Mongodb have support JS function like store procedure, function in SQL Server. Does Mongodb have to support Job Schedule? How do you do on it?

Thanks and Regards.

William Zola

unread,
Oct 3, 2012, 12:58:56 PM10/3/12
to mongod...@googlegroups.com


Hi Tom!

1) You should avoid using MongoDB stored JavaScript procedures if you possibly can.  The JavaScript engine is single-threaded.  If you run critical processes using the JavaScript stored procedures you are likely to have performance problems.

2) MongoDB currently does not have any ability to schedule any tasks to run.  There is an existing SERVER ticket with a request to add this functionality.  You can follow this ticket and vote it up here: https://jira.mongodb.org/browse/SERVER-2573

3) If you want to schedule a task to run in MongoDB, the best way to do this is with the operating system scheduler.  For example, 'cron' on Unix/Linux.

Have a great day!

 -William

Tom Vo

unread,
Oct 3, 2012, 10:45:55 PM10/3/12
to mongod...@googlegroups.com
Hi William
1) As your guide, I should not use Stored JavaScript Procedures on MongoDB. I have to execute JavaScript file on Mongo Client. 

2) You said that the JavaScript engine is single-threaded. That's mean MongoDB will be write locked when this script have not been finished. Could you give me document introduce about them? 

Thank you for your reply and kindly supports.

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb



--

Thanks and Best Regards
-------------------------------------------------------------------------------------------------------------
Tom Vo

Sam Millman

unread,
Oct 4, 2012, 4:58:47 AM10/4/12
to mongod...@googlegroups.com
Server-side execution will lock yes.

I am unsure why you need to run a file in the mongo client application from your own server side application.

Why can you not run this from your application directly?

Tom Vo

unread,
Oct 4, 2012, 5:12:13 AM10/4/12
to mongod...@googlegroups.com
Hi Wiliam

I need summary data from some collections and insert to other collection. I setup Mongodb on Windows Server 2008 and used to Task Schedule to run it.

TOM

Sam Millman

unread,
Oct 4, 2012, 5:15:39 AM10/4/12
to mongod...@googlegroups.com
If this is a one time event, guessing not from the task Schedule instance, then it is ok.

Normally you will find it more performant to do multiple runs of this fro your own server-side coding like C# or C++.

William Zola

unread,
Oct 9, 2012, 4:58:30 PM10/9/12
to mongod...@googlegroups.com

Hi Tom!

To answer your questions:

1) The JavaScript engine does not take a read lock or a write lock.  There is a separate JavaScript lock.  You can have multiple readers or writers while a JavaScript thread is executing, but you cannot have two threads using JavaScript running at the same time.

This is not a limitation of MongoDB.  This is a limitation of the SpiderMonkey JavaScript engine that MongoDB uses.

Ref:
 - https://github.com/mongodb/mongo/blob/master/src/mongo/scripting/engine_spidermonkey.cpp#L60

If your JavaScript code reads or writes to the database, then -- and only then -- will it take a read lock or write lock, as necessary.

2) If you need to run regular scheduled jobs, then running them with Task Scheduler is a good way to do it.

Let me know if you have further questions.  Have a great day!

 -William

Tom Vo

unread,
Oct 9, 2012, 9:05:00 PM10/9/12
to mongod...@googlegroups.com
Dear William
Thank you again for your kindly support.
Have a great day.
TOM Vo

Reply all
Reply to author
Forward
0 new messages