Skip to content

Commit 0abc804

Browse files
steverenkay-kim
authored andcommitted
DOCS-9744: $sample can only use a random cursor if it is the first stage in the pipeline
Signed-off-by: kay <[email protected]>
1 parent 4aa659d commit 0abc804

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

source/reference/operator/aggregation/sample.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ Definition
2828
Behavior
2929
--------
3030

31-
In order to get N random documents:
31+
:pipeline:`$sample` uses one of two methods to obtain N random
32+
documents, depending on the size of the collection, the size of N,
33+
and ``$sample``'s position in the pipeline.
3234

33-
- If N is greater than or equal to 5% of the total documents in the
34-
collection, :pipeline:`$sample` performs a collection scan, performs
35-
a sort, and then select the top N documents. As such, the
36-
:pipeline:`$sample` stage is subject to the :ref:`sort memory
37-
restrictions <sort-memory-limit>`.
35+
If all the following conditions are met, ``$sample`` uses a
36+
pseudo-random cursor to select documents:
3837

39-
- If N is less than 5% of the total documents in the collection,
38+
- ``$sample`` is the first stage of the pipeline
39+
- N is less than 5% of the total documents in the collection
40+
- The collection contains more than 100 documents
4041

41-
- If using :doc:`/core/wiredtiger`, :pipeline:`$sample` uses a
42-
pseudo-random cursor over the collection to sample N documents.
43-
44-
- If using :doc:`/core/mmapv1`, :pipeline:`$sample` uses the ``_id``
45-
index to randomly select N documents.
42+
If any of the above conditions are NOT met, ``$sample`` performs a
43+
collection scan followed by a random sort to select N documents. In
44+
this case, the :pipeline:`$sample` stage is subject to the
45+
:ref:`sort memory restrictions <sort-memory-limit>`.
4646

4747
.. warning::
4848

0 commit comments

Comments
 (0)