Skip to content

Commit b86f7ba

Browse files
ianf-mongodbjeff-allen-mongo
authored andcommitted
DOCSP-10228 lookup and graphlookup now works on sharded collections
1 parent e54136b commit b86f7ba

File tree

5 files changed

+35
-71
lines changed

5 files changed

+35
-71
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Starting in MongoDB 5.1,
2+
the :pipeline:`$lookup` and :pipeline:`$graphLookup` aggregation stages
3+
support :ref:`sharded collections <sharded-cluster>` in the ``from``
4+
parameter.
5+
6+
In previous versions of MongoDB, ``$lookup`` and ``$graphLookup``
7+
only allowed for unsharded ``from`` collections.

source/reference/operator/aggregation/graphLookup.txt

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ Definition
8282
- Target collection for the :pipeline:`$graphLookup`
8383
operation to search, recursively matching the
8484
``connectFromField`` to the ``connectToField``.
85-
The ``from`` collection cannot be
86-
sharded and must be in the same
85+
The ``from`` collection must be in the same
8786
database as any other collections used in the operation.
88-
For information, see :ref:`graphLookup-sharded-collections`.
87+
88+
Starting in MongoDB 5.1, the collection specified in the
89+
``from`` parameter can be sharded.
8990

9091
* - ``startWith``
9192

@@ -162,28 +163,8 @@ Considerations
162163
Sharded Collections
163164
~~~~~~~~~~~~~~~~~~~
164165

165-
The collection specified in ``from`` cannot be
166-
:doc:`sharded</sharding>`. However, the collection on which you run the
167-
:method:`~db.collection.aggregate()` method can be sharded. That is, in
168-
the following:
169-
170-
.. code-block:: javascript
171-
172-
db.collection.aggregate([
173-
{ $graphLookup: { from: "fromCollection", ... } }
174-
])
175-
176-
- The ``collection`` can be sharded.
177-
178-
- The ``fromCollection`` cannot be sharded.
179-
180-
To join multiple sharded collections, consider:
181-
182-
- Modifying client applications to perform manual lookups instead of
183-
using the :pipeline:`$graphLookup` aggregation stage.
184-
185-
- If possible, using an :ref:`embedded data model
186-
<data-modeling-embedding>` that removes the need to join collections.
166+
Starting in MongoDB 5.1, you can specify :doc:`sharded collections </sharding>`
167+
in the ``from`` parameter of :pipeline:`$graphLookup` stages.
187168

188169
Max Depth
189170
~~~~~~~~~

source/reference/operator/aggregation/lookup.txt

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ The :pipeline:`$lookup` takes a document with these fields:
6262
- .. _lookup-eq-from:
6363

6464
Specifies the collection in the *same* database to perform
65-
the join with. The ``from`` collection cannot be sharded. For
66-
details, see :ref:`lookup-sharded-collections`.
65+
the join with.
66+
67+
Starting in MongoDB 5.1, the collection specified in the ``from``
68+
parameter can be sharded.
6769

6870
* - :ref:`localField <lookup-eq-localField>`
6971

@@ -178,8 +180,9 @@ The :pipeline:`$lookup` stage accepts a document with these fields:
178180
- .. _lookup-join-from:
179181

180182
Specifies the collection in the *same* database to perform the
181-
join operation. The joined collection cannot be sharded (see
182-
:ref:`lookup-sharded-collections`).
183+
join operation.
184+
185+
Starting in MongoDB 5.1, the ``from`` collection can be sharded.
183186

184187
* - :ref:`let <lookup-join-let>`
185188

@@ -282,8 +285,9 @@ The :pipeline:`$lookup` accepts a document with these fields:
282285
- .. _lookup-concise-correlated-subquery-from:
283286

284287
Specifies the foreign collection in the *same* database to join
285-
to the local collection. The foreign collection cannot be sharded
286-
(see :ref:`lookup-sharded-collections`).
288+
to the local collection.
289+
290+
Starting in MongoDB 5.1, the ``from`` collection can be sharded.
287291

288292
* - :ref:`localField
289293
<lookup-concise-correlated-subquery-localField>`
@@ -396,47 +400,11 @@ Restrictions
396400

397401
.. _lookup-sharded-collections:
398402

399-
Sharded Collection Restrictions
400-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
401-
402-
In the :pipeline:`$lookup` stage, the ``from`` collection cannot be
403-
:doc:`sharded</sharding>`. However, the collection on which you run the
404-
:method:`~db.collection.aggregate()` method can be sharded.
405-
Specifically, in this example:
406-
407-
.. code-block:: javascript
408-
409-
db.collection.aggregate([
410-
{ $lookup: { from: "fromCollection", ... } }
411-
])
412-
413-
- The ``collection`` can be sharded.
414-
415-
- The ``fromCollection`` cannot be sharded.
416-
417-
To join a sharded collection with an unsharded collection, run the
418-
aggregation on the sharded collection and lookup the unsharded
419-
collection. For example:
420-
421-
.. code-block:: javascript
422-
423-
db.shardedCollection.aggregate([
424-
{ $lookup: { from: "unshardedCollection", ... } }
425-
])
426-
427-
Alternatively, or to join multiple sharded collections, consider:
428-
429-
- Modifying client applications to perform manual lookups instead of
430-
using the :pipeline:`$lookup` aggregation stage.
431-
432-
- If possible, using an :ref:`embedded data model
433-
<data-modeling-embedding>` that removes the need to join collections.
403+
Sharded Collections
404+
~~~~~~~~~~~~~~~~~~~
434405

435-
- If possible, using an `Atlas Data Lake
436-
<https://docs.mongodb.com/datalake/>`__
437-
`$lookup
438-
<https://docs.mongodb.com/datalake/reference/pipeline/lookup-stage/>`__
439-
pipeline stage to lookup a sharded collection.
406+
Starting in MongoDB 5.1, you can specify :doc:`sharded collections </sharding>`
407+
in the ``from`` parameter of :pipeline:`$lookup` stages.
440408

441409
Examples
442410
--------

source/release-notes/5.1-compatibility.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Removed Parameters
3232

3333
.. include:: /includes/5.1/removed-parameters.rst
3434

35+
Aggregation
36+
-----------
37+
3538
Removed Index Types
3639
-------------------
3740

source/release-notes/5.1.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ Aggregation
2626

2727
.. _5.1-rel-notes-new-agg-operators:
2828

29+
$lookup and $graphLookup with sharded collections
30+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31+
32+
.. include:: /includes/5.1-fact-sharded-lookup-graphlookup.rst
33+
2934
New Aggregation Operators
3035
~~~~~~~~~~~~~~~~~~~~~~~~~
3136

0 commit comments

Comments
 (0)