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#L60If 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