eval( function, arguments )
Deprecated since version 3.0.
mongoshell wraps the
evalcommand. Therefore, the helper method shares the characteristics and behavior of the underlying command with one exception:
db.eval()method does not support the
The method accepts the following parameters:
Parameter Type Description
db.eval() blocks all other read and write operations to the database while the
db.eval() operation runs.
eval command with
nolock set to
Changed in version 2.6.
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 following is an example of the
dbin the function refers to the current database.
"eliot"is the argument passed to the function, and corresponds to the
5is an argument to the function and corresponds to the
If an error occurs,
db.eval() throws an exception. The following is an example of an invalid function that uses the variable
x without declaring it as an argument:
The statement results in the following exception: