Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/includes/uncorrelated-subquery.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Starting in MongoDB 5.0, for an uncorrelated subquery in a
:pipeline:`$lookup` pipeline stage containing a :pipeline:`$sample`
stage, the :expression:`$sampleRate` operator, or the
:expression:`$rand` operator, the subquery is always run again if
repeated. Previously, depending on the subquery output size, either the
subquery output was cached or the subquery was run again.
14 changes: 10 additions & 4 deletions source/reference/operator/aggregation/lookup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ In MongoDB, a correlated subquery is a :ref:`pipeline
document fields from a joined collection. An uncorrelated subquery does
not reference joined fields.

.. note::

.. include:: /includes/uncorrelated-subquery.rst

MongoDB correlated subqueries are comparable to SQL correlated
subqueries, where the inner query references outer query values. An
SQL uncorrelated subquery does not reference outer query values.
Expand Down Expand Up @@ -780,11 +784,13 @@ the ``warehouses`` collection:
Perform an Uncorrelated Subquery with ``$lookup``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionchanged:: 3.6
An aggregation pipeline :pipeline:`$lookup` stage can execute a pipeline
on the joined collection, which allows uncorrelated subqueries. An
uncorrelated subquery does not reference the joined document fields.

.. note::

MongoDB 3.6 adds support for executing a pipeline on the joined
collection, which allows uncorrelated subqueries. An uncorrelated
subquery does not reference the joined document fields.
.. include:: /includes/uncorrelated-subquery.rst

Create a collection ``absences`` with these documents:

Expand Down
7 changes: 7 additions & 0 deletions source/release-notes/5.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ stage supports :ref:`concise correlated subqueries
<lookup-syntax-concise-correlated-subquery>` that improve joins between
collections.

``$lookup`` Stage: Uncorrelated Subqueries
``````````````````````````````````````````

.. include:: /includes/uncorrelated-subquery.rst

See :ref:`lookup-uncorrelated-subquery`.

.. _5.0-rel-notes-auditing:

Auditing
Expand Down