@@ -24,7 +24,7 @@ Definition
24
24
the "joined" collection. The :pipeline:`$lookup` stage passes these
25
25
reshaped documents to the next stage.
26
26
27
- Starting in MongoDB 5.1, :pipeline:`$lookup` works across sharded
27
+ Starting in MongoDB 5.1, you can use :pipeline:`$lookup` with sharded
28
28
collections.
29
29
30
30
To combine elements from two different collections, use the
@@ -117,19 +117,25 @@ The :pipeline:`$lookup` takes a document with these fields:
117
117
already exists in the input document, the existing field is
118
118
*overwritten*.
119
119
120
- The operation would correspond to the following pseudo-SQL statement:
120
+ The operation corresponds to this pseudo-SQL statement:
121
121
122
122
.. code-block:: sql
123
+ :copyable: false
123
124
124
- SELECT *, <output array field>
125
- FROM collection
126
- WHERE <output array field> IN (
127
- SELECT *
125
+ SELECT *, (
126
+ SELECT ARRAY_AGG(*)
128
127
FROM <collection to join>
129
128
WHERE <foreignField> = <collection.localField>
130
- );
129
+ ) AS <output array field>
130
+ FROM collection;
131
131
132
- See these examples:
132
+ .. note::
133
+
134
+ The SQL statements on this page are included for comparison to the
135
+ MongoDB aggregation pipeline syntax. The SQL statements aren't
136
+ runnable.
137
+
138
+ For MongoDB examples, see these pages:
133
139
134
140
- :ref:`lookup-single-equality-example`
135
141
- :ref:`unwind-example`
@@ -246,6 +252,7 @@ The :pipeline:`$lookup` stage accepts a document with these fields:
246
252
The operation corresponds to this pseudo-SQL statement:
247
253
248
254
.. code-block:: sql
255
+ :copyable: false
249
256
250
257
SELECT *, <output array field>
251
258
FROM collection
@@ -377,6 +384,7 @@ The :pipeline:`$lookup` accepts a document with these fields:
377
384
The operation corresponds to this pseudo-SQL statement:
378
385
379
386
.. code-block:: sql
387
+ :copyable: false
380
388
381
389
SELECT *, <output array field>
382
390
FROM localCollection
@@ -685,6 +693,7 @@ The operation returns these documents:
685
693
The operation corresponds to this pseudo-SQL statement:
686
694
687
695
.. code-block:: sql
696
+ :copyable: false
688
697
689
698
SELECT *, inventory_docs
690
699
FROM orders
@@ -946,6 +955,7 @@ The operation returns these documents:
946
955
The operation corresponds to this pseudo-SQL statement:
947
956
948
957
.. code-block:: sql
958
+ :copyable: false
949
959
950
960
SELECT *, stockdata
951
961
FROM orders
@@ -1061,6 +1071,7 @@ The operation returns the following:
1061
1071
The operation corresponds to this pseudo-SQL statement:
1062
1072
1063
1073
.. code-block:: sql
1074
+ :copyable: false
1064
1075
1065
1076
SELECT *, holidays
1066
1077
FROM absences
0 commit comments