Instinctively I'd be very weary of using db.eval and find another way. What version of MongoDB are you using ? Does the code take user input that is liable to code injection ? This function has some severe side effects, for example, it blocks all reads and writes.
The function has been deprecated as of MongoDB 3.0 - the techies at MongoDB must have thought there was a good reason not to have that function at all, so you may want to take this into consideration !