@@ -27,7 +27,7 @@ Definition
2727 the "joined" collection. The :pipeline:`$lookup` stage passes these
2828 reshaped documents to the next stage.
2929
30- Starting in MongoDB 5.1, :pipeline:`$lookup` works across sharded
30+ Starting in MongoDB 5.1, you can use :pipeline:`$lookup` with sharded
3131 collections.
3232
3333 To combine elements from two different collections, use the
@@ -120,19 +120,25 @@ The :pipeline:`$lookup` takes a document with these fields:
120120 already exists in the input document, the existing field is
121121 *overwritten*.
122122
123- The operation would correspond to the following pseudo-SQL statement:
123+ The operation corresponds to this pseudo-SQL statement:
124124
125125.. code-block:: sql
126+ :copyable: false
126127
127- SELECT *, <output array field>
128- FROM collection
129- WHERE <output array field> IN (
130- SELECT *
128+ SELECT *, (
129+ SELECT ARRAY_AGG(*)
131130 FROM <collection to join>
132131 WHERE <foreignField> = <collection.localField>
133- );
132+ ) AS <output array field>
133+ FROM collection;
134134
135- See these examples:
135+ .. note::
136+
137+ The SQL statements on this page are included for comparison to the
138+ MongoDB aggregation pipeline syntax. The SQL statements aren't
139+ runnable.
140+
141+ For MongoDB examples, see these pages:
136142
137143- :ref:`lookup-single-equality-example`
138144- :ref:`unwind-example`
@@ -249,6 +255,7 @@ The :pipeline:`$lookup` stage accepts a document with these fields:
249255The operation corresponds to this pseudo-SQL statement:
250256
251257.. code-block:: sql
258+ :copyable: false
252259
253260 SELECT *, <output array field>
254261 FROM collection
@@ -380,6 +387,7 @@ The :pipeline:`$lookup` accepts a document with these fields:
380387The operation corresponds to this pseudo-SQL statement:
381388
382389.. code-block:: sql
390+ :copyable: false
383391
384392 SELECT *, <output array field>
385393 FROM localCollection
@@ -681,6 +689,7 @@ The operation returns these documents:
681689The operation corresponds to this pseudo-SQL statement:
682690
683691.. code-block:: sql
692+ :copyable: false
684693
685694 SELECT *, inventory_docs
686695 FROM orders
@@ -942,6 +951,7 @@ The operation returns these documents:
942951The operation corresponds to this pseudo-SQL statement:
943952
944953.. code-block:: sql
954+ :copyable: false
945955
946956 SELECT *, stockdata
947957 FROM orders
@@ -1057,6 +1067,7 @@ The operation returns the following:
10571067The operation corresponds to this pseudo-SQL statement:
10581068
10591069.. code-block:: sql
1070+ :copyable: false
10601071
10611072 SELECT *, holidays
10621073 FROM absences
0 commit comments