@@ -27,7 +27,7 @@ Definition
27
27
the "joined" collection. The :pipeline:`$lookup` stage passes these
28
28
reshaped documents to the next stage.
29
29
30
- Starting in MongoDB 5.1, :pipeline:`$lookup` works across sharded
30
+ Starting in MongoDB 5.1, you can use :pipeline:`$lookup` with sharded
31
31
collections.
32
32
33
33
To combine elements from two different collections, use the
@@ -120,19 +120,25 @@ The :pipeline:`$lookup` takes a document with these fields:
120
120
already exists in the input document, the existing field is
121
121
*overwritten*.
122
122
123
- The operation would correspond to the following pseudo-SQL statement:
123
+ The operation corresponds to this pseudo-SQL statement:
124
124
125
125
.. code-block:: sql
126
+ :copyable: false
126
127
127
- SELECT *, <output array field>
128
- FROM collection
129
- WHERE <output array field> IN (
130
- SELECT *
128
+ SELECT *, (
129
+ SELECT ARRAY_AGG(*)
131
130
FROM <collection to join>
132
131
WHERE <foreignField> = <collection.localField>
133
- );
132
+ ) AS <output array field>
133
+ FROM collection;
134
134
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:
136
142
137
143
- :ref:`lookup-single-equality-example`
138
144
- :ref:`unwind-example`
@@ -249,6 +255,7 @@ The :pipeline:`$lookup` stage accepts a document with these fields:
249
255
The operation corresponds to this pseudo-SQL statement:
250
256
251
257
.. code-block:: sql
258
+ :copyable: false
252
259
253
260
SELECT *, <output array field>
254
261
FROM collection
@@ -380,6 +387,7 @@ The :pipeline:`$lookup` accepts a document with these fields:
380
387
The operation corresponds to this pseudo-SQL statement:
381
388
382
389
.. code-block:: sql
390
+ :copyable: false
383
391
384
392
SELECT *, <output array field>
385
393
FROM localCollection
@@ -681,6 +689,7 @@ The operation returns these documents:
681
689
The operation corresponds to this pseudo-SQL statement:
682
690
683
691
.. code-block:: sql
692
+ :copyable: false
684
693
685
694
SELECT *, inventory_docs
686
695
FROM orders
@@ -942,6 +951,7 @@ The operation returns these documents:
942
951
The operation corresponds to this pseudo-SQL statement:
943
952
944
953
.. code-block:: sql
954
+ :copyable: false
945
955
946
956
SELECT *, stockdata
947
957
FROM orders
@@ -1057,6 +1067,7 @@ The operation returns the following:
1057
1067
The operation corresponds to this pseudo-SQL statement:
1058
1068
1059
1069
.. code-block:: sql
1070
+ :copyable: false
1060
1071
1061
1072
SELECT *, holidays
1062
1073
FROM absences
0 commit comments