Skip to content

Commit 2147ffb

Browse files
authored
DOCSP-21763 documents new allowDiskUseByDefault param (#963)
* documents allowDiskUseByDefault param * internal review feedback * additional internal review feedback * additional internal review feedback * clarifies that { allowDiskUse: true } can still be used to spill working data to disk when allowDiskUseByDefault is set to false * internal feedback * second round of review * external review feedback * external * clarification * includify * clean-up * more consistency between sort and sortByCount * param desc * includify * more includification * continuation * continuation * more includification * update extracts-views blurb to use include * includes * consolidate * consolidation * remove empty file * updates cursor.allowDiskUse * parenthetical re allowDiskUseByDefault default setting * external review * external review
1 parent 3244b09 commit 2147ffb

File tree

12 files changed

+140
-78
lines changed

12 files changed

+140
-78
lines changed

source/includes/extracts-views.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ content: |
3434
3535
- The view's underlying aggregation pipeline is subject to the 100
3636
megabyte memory limit for blocking sort and blocking group
37-
operations. Starting in MongoDB 4.4, you can issue a
38-
:dbcommand:`find` command with ``allowDiskUse: true`` on the view
39-
to allow MongoDB to use temporary files for blocking sort and group
40-
operations.
37+
operations.
38+
39+
.. include:: /includes/fact-allowDiskUseByDefault.rst
40+
41+
Starting in MongoDB 4.4, you can specify the ``allowDiskUse``
42+
option on a :dbcommand:`find` command. This allows the application
43+
to control whether disk use is allowed when running a
44+
:dbcommand:`find` command against a view.
4145
4246
Prior to MongoDB 4.4, only the :dbcommand:`aggregate` command
4347
accepted the ``allowDiskUse`` option.

source/includes/fact-agg-memory-limit.rst

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
.. FYI -- 2.5.3 introduced the limit to $group and changed the limit for
22
$sort from 10% to 100 MB.
33
4-
Each individual pipeline stage has a limit of 100 megabytes of RAM. By
5-
default, if a stage exceeds this limit, MongoDB produces an error. For
6-
some pipeline stages you can allow pipeline processing to take up more
7-
space by using the :ref:`allowDiskUse <aggregate-cmd-allowDiskUse>`
8-
option to enable aggregation pipeline stages to write data to temporary
9-
files.
4+
Starting in MongoDB 6.0, the :parameter:`allowDiskUseByDefault`
5+
parameter controls whether pipeline stages that require more than 100
6+
megabytes of memory to execute write temporary files to disk by
7+
default.
8+
9+
- If :parameter:`allowDiskUseByDefault` is set to ``true``, pipeline
10+
stages that require more than 100 megabytes of memory to execute
11+
write temporary files to disk by default. You can disable writing
12+
temporary files to disk for specific ``find`` or ``aggregate``
13+
commands using the ``{ allowDiskUse: false }`` option.
14+
15+
- If :parameter:`allowDiskUseByDefault` is set to ``false``, pipeline
16+
stages that require more than 100 megabytes of memory to execute
17+
raise an error by default. You can enable writing temporary files to
18+
disk for specific ``find`` or ``aggregate`` using
19+
the ``{ allowDiskUse: true }`` option.
1020

1121
The :pipeline:`$search` aggregation stage is not restricted to
1222
100 megabytes of RAM because it runs in a separate process.
1323

14-
Examples of stages that can spill to disk when :ref:`allowDiskUse
15-
<aggregate-cmd-allowDiskUse>` is ``true`` are:
24+
Examples of stages that can write temporary files to disk when
25+
:ref:`allowDiskUse <aggregate-cmd-allowDiskUse>` is ``true`` are:
1626

1727
- :pipeline:`$bucket`
1828
- :pipeline:`$bucketAuto`
1929
- :pipeline:`$group`
30+
- :pipeline:`$setWindowFields`
2031
- :pipeline:`$sort` when the sort operation is not supported by an
2132
index
2233
- :pipeline:`$sortByCount`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Use this option to override :parameter:`allowDiskUseByDefault`
2+
for a specific query. You can use this option to either:
3+
4+
- Prohibit disk use on a system where disk use is allowed by
5+
default.
6+
- Allow disk use on a system where disk use is prohibited by
7+
default.
8+
9+
Starting in MongoDB 6.0, if :parameter:`allowDiskUseByDefault` is set
10+
to ``true`` and the server requires more than 100 megabytes of memory
11+
for a pipeline execution stage, MongoDB automatically writes
12+
temporary files to disk unless the query specifies
13+
``{ allowDiskUse: false }``.
14+
15+
For details, see :parameter:`allowDiskUseByDefault`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Starting in MongoDB 6.0, pipeline stages that require more than 100
2+
megabytes of memory to execute write temporary files to disk by
3+
default. In earlier verisons of MongoDB, you must pass
4+
``{ allowDiskUse: true }`` to individual ``find`` and ``aggregate``
5+
commands to enable this behavior.
6+
7+
Individual ``find`` and ``aggregate`` commands may override the
8+
:parameter:`allowDiskUseByDefault` parameter by either:
9+
10+
- Using ``{ allowDiskUse: true }`` to allow writing temporary files out
11+
to disk when ``allowDiskUseByDefault`` is set to ``false``
12+
13+
- Using ``{ allowDiskUse: false }`` to probibit writing temporary files
14+
out to disk when ``allowDiskUseByDefault`` is set to ``true``

source/reference/command/aggregate.txt

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,9 @@ arguments:
105105

106106
- boolean
107107

108-
- Optional. Enables writing to temporary files. When set to
109-
``true``, aggregation stages can write data to the :file:`_tmp`
110-
subdirectory in the :setting:`~storage.dbPath` directory.
108+
- Optional.
111109

112-
By default, ``allowDiskUse`` is ``false``.
110+
.. include:: /includes/fact-allowDiskUse-option-6.0.rst
113111

114112
.. include:: /includes/extracts/4.2-changes-usedDisk.rst
115113

@@ -436,23 +434,10 @@ to ``true`` to return information about the aggregation operation.
436434
:method:`db.collection.aggregate()` method
437435

438436

439-
Aggregate Data using External Sort
440-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
441-
442-
Each individual pipeline stage has :ref:`a limit of 100 megabytes of RAM
443-
<agg-memory-restrictions>`. By default, if a stage exceeds this limit,
444-
MongoDB produces an error. To allow pipeline processing to take up
445-
more space, set the :ref:`allowDiskUse <aggregate-cmd-allowDiskUse>`
446-
option to ``true`` to enable writing data to temporary files, as in the
447-
following example:
448-
449-
.. code-block:: javascript
437+
Interaction with ``allowDiskUseByDefault``
438+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450439

451-
db.stocks.aggregate( [
452-
{ $sort : { cusip : 1, date: 1 } }
453-
],
454-
{ allowDiskUse: true }
455-
)
440+
.. include:: /includes/fact-allowDiskUseByDefault.rst
456441

457442
.. include:: /includes/extracts/4.2-changes-usedDisk.rst
458443

source/reference/command/find.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,7 @@ The command accepts the following fields:
378378

379379
- Optional.
380380

381-
Use ``allowDiskUse`` to allow MongoDB to use temporary files on
382-
disk to store data exceeding the 100 megabyte memory limit while
383-
processing a non-indexed ("blocking") sort operation. If MongoDB
384-
requires using more than 100 megabytes of memory for a blocking
385-
sort operation, MongoDB returns an error *unless* the query
386-
specifies ``allowDiskUse``. See :ref:`sort-index-use` for more
387-
information on blocking sort operations.
381+
.. include:: /includes/fact-allowDiskUse-option-6.0.rst
388382

389383
``allowDiskUse`` has no effect if MongoDB can satisfy the
390384
specified :ref:`sort <find-cmd-sort>` using an index, *or* if the

source/reference/method/cursor.allowDiskUse.txt

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ Definition
2020

2121
.. include:: /includes/fact-mongosh-shell-method.rst
2222

23-
:method:`~cursor.allowDiskUse()` allows MongoDB to use temporary
24-
files on disk to store data exceeding the 100 megabyte system memory
25-
limit while processing a blocking sort operation. If MongoDB requires
26-
using more than 100 megabytes of system memory for the blocking sort
27-
operation, MongoDB returns an error *unless* the query specifies
28-
:method:`cursor.allowDiskUse()`.
23+
Use :method:`~cursor.allowDiskUse()` to either allow or prohibit
24+
writing temporary files on disk when a pipeline stage exceeds
25+
the 100 megabyte limit. Starting in MongoDB 6.0, operations that
26+
require greater than 100 megabytes of memory automatically write
27+
data to temporary files by default.
2928

3029
:method:`~cursor.allowDiskUse()` has the following form:
3130

@@ -39,6 +38,33 @@ operations.
3938
Behavior
4039
--------
4140

41+
Interaction with ``allowDiskUseByDefault``
42+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43+
44+
Starting in MongoDB 6.0, pipeline stages that require more than 100
45+
megabytes of memory to execute write temporary files to disk by
46+
default.
47+
48+
.. note::
49+
50+
The following only applies to the legacy ``mongo`` shell in MongoDB
51+
v6.0. In previous versions of the legacy ``mongo`` shell,
52+
``.allowDiskUse(false)`` and ``.allowDiskUse(true)`` have the same
53+
effect.
54+
55+
If :parameter:`allowDiskUseByDefault` is ``true`` (this is the default):
56+
57+
- ``.allowDiskUse()`` has no additional effect
58+
- ``.allowDiskUse(true)`` has no additional effect
59+
- ``.allowDiskUse(false)`` prohibits the query from writing temporary
60+
files to disk
61+
62+
If :parameter:`allowDiskUseByDefault` is ``false``:
63+
64+
- ``.allowDiskUse()`` enables writing temporary files to disk
65+
- ``.allowDiskUse(true)`` enables writing temporary files to disk
66+
- ``.allowDiskUse(false)`` has no additional effect
67+
4268
Supports Large Non-Indexed Sorts Only
4369
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4470

source/reference/method/db.collection.aggregate.txt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -404,26 +404,10 @@ You can view more verbose explain output by passing the
404404

405405
.. _example-aggregate-method-external-sort:
406406

407-
Perform Large Sort Operation with External Sort
408-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
407+
Interaction with ``allowDiskUseByDefault``
408+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
409409

410-
Each individual pipeline stage has :ref:`a limit of 100 megabytes of RAM
411-
<agg-memory-restrictions>`. By default, if a stage exceeds this limit,
412-
MongoDB produces an error. To allow pipeline processing to take up
413-
more space, set the :ref:`allowDiskUse <aggregate-cmd-allowDiskUse>`
414-
option to ``true`` to enable writing data to temporary files, as in the
415-
following example:
416-
417-
.. code-block:: javascript
418-
419-
var results = db.stocks.aggregate(
420-
[
421-
{ $sort : { cusip : 1, date: 1 } }
422-
],
423-
{
424-
allowDiskUse: true
425-
}
426-
)
410+
.. include:: /includes/fact-allowDiskUseByDefault.rst
427411

428412
.. include:: /includes/extracts/4.2-changes-usedDisk.rst
429413

source/reference/operator/aggregation/sort.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,10 @@ documents. See :expression:`$meta` for more information.
209209
``$sort`` and Memory Restrictions
210210
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211211

212-
The :pipeline:`$sort` stage has a limit of 100 megabytes of RAM for
213-
in-memory sorts. By default, if the stage exceeds this limit,
214-
:pipeline:`$sort` produces an error. To allow pipeline processing to
215-
take up more space, use the :ref:`allowDiskUse
216-
<aggregate-cmd-allowDiskUse>` option to enable aggregation pipeline
217-
stages to write data to temporary files.
212+
``$sort`` is subject to the 100 megabyte memory usage limit, but is
213+
able to write temporary files to disk if additional space is required.
214+
215+
.. include:: /includes/fact-allowDiskUseByDefault.rst
218216

219217
.. seealso::
220218

source/reference/operator/aggregation/sortByCount.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ Considerations
8181

8282
.. _sortbycount-memory-limit:
8383

84-
``$count`` and Memory Restrictions
85-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86-
87-
The :pipeline:`$sortByCount` stage has a limit of 100 megabytes of RAM.
88-
By default, if the stage exceeds this limit, :pipeline:`$sortByCount`
89-
returns an error. To allow more space for stage processing, use the
90-
:ref:`allowDiskUse <aggregate-cmd-allowDiskUse>` option to enable
91-
aggregation pipeline stages to write data to temporary files.
84+
``$sortByCount`` and Memory Restrictions
85+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86+
87+
``$sortByCount`` is subject to the 100 megabyte memory usage limit, but
88+
is able to write temporary files to disk if additional space is
89+
required.
90+
91+
.. include:: /includes/fact-allowDiskUseByDefault.rst
9292

9393
.. seealso::
9494

0 commit comments

Comments
 (0)