Optional. An array of arguments to pass to the JavaScript function. Omit if the function does not take arguments.

nolock

boolean

Optional. By default, eval takes a global write lock before
evaluating the JavaScript function. As a result, eval
blocks all other read and write operations to the database while the
eval operation runs. Set nolock to true on the
eval command to prevent the eval command
from taking the global write lock before evaluating the
JavaScript. nolock does not impact whether operations within the
JavaScript code itself takes a write lock.

JavaScript in MongoDB

Although eval uses JavaScript, most interactions
with MongoDB do not use JavaScript but use an idiomatic driver in the language of the interacting
application.

By default, eval takes a global write lock while evaluating the
JavaScript function. As a result, eval blocks all other read and
write operations to the database while the eval operation runs.

To prevent the taking of the global write lock while evaluating the
JavaScript code, use the eval command with nolock set to
true. nolock does not impact whether the operations within the
JavaScript code take write locks.

If authorization is enabled, you must have access to all actions
on all resources in order to run
eval. Providing such access is not recommended, but if your
organization requires a user to run eval, create a role that
grants anyAction on anyResource. Do not
assign this role to any other user.

The helper db.eval() in the mongo shell wraps the
eval command. Therefore, the helper method shares the
characteristics and behavior of the underlying command with one
exception: db.eval() method does not support the nolock
option.