|
22 | 22 |
|
23 | 23 | The command contains the following fields:
|
24 | 24 |
|
25 |
| - :param JavaScript function: |
| 25 | + :field JavaScript function: |
26 | 26 |
|
27 | 27 | A JavaScript function.
|
28 | 28 |
|
|
43 | 43 | // ...
|
44 | 44 | }
|
45 | 45 |
|
46 |
| - :param arguments: |
| 46 | + :field arguments: |
47 | 47 |
|
48 | 48 | A list of arguments to pass to the JavaScript ``function`` if
|
49 | 49 | the function accepts arguments. Omit if the ``function`` does
|
|
56 | 56 |
|
57 | 57 | :field boolean nolock:
|
58 | 58 |
|
59 |
| - Optional. Specifies whether to disable the write lock. By |
60 |
| - default, :dbcommand:`eval` takes a write lock. There are |
61 |
| - circumstances where the :dbcommand:`eval` executes a strictly |
62 |
| - read-only operation that does not need to block other |
63 |
| - operations. If ``nolock`` is ``true``, the |
64 |
| - :dbcommand:`eval` does not take a write lock. |
65 |
| - |
66 |
| - .. warning:: |
67 |
| - |
68 |
| - Do not disable the write lock if the function may modify |
69 |
| - the contents of the database in any way. |
| 59 | + Optional. By default, :dbcommand:`eval` takes a global write lock |
| 60 | + before evaluating the JavaScript function. If ``nolock`` is |
| 61 | + ``true``, the :dbcommand:`eval` does not take this global write |
| 62 | + lock before evaluating the function. The flag does not impact |
| 63 | + whether the JavaScript code itself takes a write lock. |
70 | 64 |
|
71 | 65 | Consider the following example which uses :dbcommand:`eval` to
|
72 | 66 | perform an increment and calculate the average on the server:
|
|
111 | 105 | },
|
112 | 106 | "eliot", 5 );
|
113 | 107 |
|
114 |
| - You cannot pass the ``nolock`` flag to the :method:`db.eval()` |
115 |
| - in the :program:`mongo` shell. |
| 108 | + The :method:`db.eval()` method does not support the ``nolock`` |
| 109 | + option. |
116 | 110 |
|
117 | 111 | If you want to use the server's interpreter, you must run
|
118 | 112 | :dbcommand:`eval`. Otherwise, the :program:`mongo` shell's
|
@@ -144,15 +138,20 @@ eval
|
144 | 138 |
|
145 | 139 | .. warning::
|
146 | 140 |
|
147 |
| - - The :method:`db.eval()` operation takes a write lock by |
148 |
| - default. This means that :dbcommand:`eval` blocks all other |
149 |
| - read and write operations to the database while the |
150 |
| - :dbcommand:`eval` operation runs. You can, however, disable |
151 |
| - the lock by setting the ``nolock`` flag to ``true`` if the |
152 |
| - :dbcommand:`eval` performs a strictly read-only operation. |
| 141 | + - The :dbcommand:`eval` command takes a global write lock by |
| 142 | + default before executing the JavaScript function. This means |
| 143 | + that :dbcommand:`eval` blocks all other read and write |
| 144 | + operations to the database while the :dbcommand:`eval` |
| 145 | + operation runs. You can, however, set the ``nolock`` flag to |
| 146 | + ``true`` to prevent the :dbcommand:`eval` command from taking a |
| 147 | + global write lock before executing the JavaScript function. The |
| 148 | + flag does not impact whether the JavaScript code itself takes |
| 149 | + a write lock. |
153 | 150 |
|
154 | 151 | - :dbcommand:`eval` also takes a JavaScript lock.
|
155 | 152 |
|
| 153 | +.. modified in 2.4 version, the JavaScript lock is up to and including version 2.2 |
| 154 | + |
156 | 155 | - Do not use :dbcommand:`eval` for long running operations as
|
157 | 156 | :dbcommand:`eval` blocks all other operations. Consider using
|
158 | 157 | :doc:`other server side code execution options
|
|
0 commit comments