Skip to content

Commit a996453

Browse files
committed
DOCS-954 eval and locks
1 parent c715a40 commit a996453

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

source/includes/fact-eval-lock.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. eval-command-nolock
2+
3+
By default, :dbcommand:`eval` takes a global write lock before
4+
evaluating the JavaScript function. This means that :dbcommand:`eval`
5+
blocks all other read and write operations to the database while the
6+
:dbcommand:`eval` operation runs. Set ``nolock`` to ``true`` to ensure
7+
that :dbcommand:`eval` does not take this global write lock before
8+
evaluating the function. The flag does not impact whether the
9+
JavaScript code itself takes a write lock.
10+
11+
.. eval-method-lock
12+
13+
The :method:`db.eval()` method takes a global write lock by default
14+
before executing the JavaScript function. This means that
15+
:method:`db.eval()` blocks all other read and write operations to the
16+
database while the :method:`db.eval()` operation runs. You can,
17+
however, use the :dbcommand:`eval` command, instead of the
18+
:method:`db.eval()` method, with the ``nolock`` flag to ``true``. See
19+
:dbcommand:`eval` command for more details.

source/reference/command/eval.txt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ eval
5454
An array of corresponding arguments to the ``function``. Omit
5555
``args`` if the ``function`` does not take arguments.
5656

57-
:field boolean nolock:
57+
:field boolean nolock: Optional.
5858

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.
59+
.. include:: /includes/fact-eval-lock.rst
60+
:end-before: eval-method-lock
6461

6562
Consider the following example which uses :dbcommand:`eval` to
6663
perform an increment and calculate the average on the server:
@@ -138,15 +135,8 @@ eval
138135

139136
.. warning::
140137

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.
138+
- .. include:: /includes/fact-eval-lock.rst
139+
:end-before: eval-method-lock
150140

151141
- :dbcommand:`eval` also takes a JavaScript lock.
152142

source/reference/method/db.eval.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,9 @@ db.eval()
9393

9494
.. warning::
9595

96-
- The :method:`db.eval()` method takes a global write lock by
97-
default before executing the JavaScript function. This means
98-
that :method:`db.eval()` blocks all other read and write
99-
operations to the database while the :method:`db.eval()`
100-
operation runs. You can, however, use the :dbcommand:`eval`
101-
command, instead of the :method:`db.eval()` method, with the
102-
``nolock`` flag to ``true``. See :dbcommand:`eval` command for
103-
more details.
104-
96+
- .. include:: /includes/fact-eval-lock.rst
97+
:start-after: eval-method-lock
98+
10599
- :method:`db.eval()` also takes a JavaScript lock.
106100

107101
.. modified in 2.4 version, the JavaScript lock is up to and including version 2.2

0 commit comments

Comments
 (0)