Skip to content

Commit c715a40

Browse files
committed
DOCS-954 eval() helper and nolock
DOCS-954 db.eval() method and nolock option DOCS-954 incorporate Scott's feedback incorporate Tad's comments DOCS-954 eval and lock
1 parent 307609e commit c715a40

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

source/reference/command/eval.txt

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ eval
2222

2323
The command contains the following fields:
2424

25-
:param JavaScript function:
25+
:field JavaScript function:
2626

2727
A JavaScript function.
2828

@@ -43,7 +43,7 @@ eval
4343
// ...
4444
}
4545

46-
:param arguments:
46+
:field arguments:
4747

4848
A list of arguments to pass to the JavaScript ``function`` if
4949
the function accepts arguments. Omit if the ``function`` does
@@ -56,17 +56,11 @@ eval
5656

5757
:field boolean nolock:
5858

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.
7064

7165
Consider the following example which uses :dbcommand:`eval` to
7266
perform an increment and calculate the average on the server:
@@ -111,8 +105,8 @@ eval
111105
},
112106
"eliot", 5 );
113107

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.
116110

117111
If you want to use the server's interpreter, you must run
118112
:dbcommand:`eval`. Otherwise, the :program:`mongo` shell's
@@ -144,15 +138,20 @@ eval
144138

145139
.. warning::
146140

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.
153150

154151
- :dbcommand:`eval` also takes a JavaScript lock.
155152

153+
.. modified in 2.4 version, the JavaScript lock is up to and including version 2.2
154+
156155
- Do not use :dbcommand:`eval` for long running operations as
157156
:dbcommand:`eval` blocks all other operations. Consider using
158157
:doc:`other server side code execution options

source/reference/method/db.eval.txt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ db.eval()
1111

1212
The :method:`db.eval()` provides the ability to run JavaScript code
1313
on the MongoDB server. It is a :program:`mongo` shell wrapper around
14-
the :dbcommand:`eval` command.
14+
the :dbcommand:`eval` command. However, unlike the :dbcommand:`eval`
15+
command, the :method:`db.eval()` method does not support the
16+
``nolock`` option.
1517

1618
The method accepts the following parameters:
1719

@@ -91,17 +93,18 @@ db.eval()
9193

9294
.. warning::
9395

94-
- The :method:`db.eval()` operation takes a write lock by
95-
default. This means that :method:`db.eval()` blocks all other
96-
read and write operations to the database while
97-
the :method:`db.eval()` operation runs. However, if you are using the
98-
:dbcommand:`eval` command using :method:`db.runCommand()`
99-
rather than the helper, you can disable the lock by setting
100-
the ``nolock`` flag to ``true`` if the :dbcommand:`eval`
101-
performs a strictly read-only operation.
102-
103-
- :method:`db.eval()` also takes a JavaScript lock which blocks
104-
all
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+
105+
- :method:`db.eval()` also takes a JavaScript lock.
106+
107+
.. modified in 2.4 version, the JavaScript lock is up to and including version 2.2
105108

106109
- Do not use :method:`db.eval()` for long running operations, as
107110
:method:`db.eval()` blocks all other operations. Consider using

0 commit comments

Comments
 (0)