12
12
:depth: 2
13
13
:class: singlecol
14
14
15
- ``$lookup`` performs a left outer join to an unsharded collection in the
16
- same database to filter in documents from the "joined" collection for
17
- processing. For more information, see
18
- :manual:`$lookup </reference/operator/aggregation/lookup/>`. In
19
- {+data-lake+}, ``$lookup`` can be used to perform a join of collections
20
- from different databases.
15
+ The MongoDB server :manual:`$lookup </reference/operator/aggregation/lookup/>`
16
+ performs a left outer join of one unsharded collection to another
17
+ unsharded collection in the same database. Lookups are useful as they
18
+ allow you to filter in documents from the "joined" collection for processing.
19
+
20
+ In {+data-lake+}, you can use ``$lookup`` to join sharded and unsharded
21
+ collections from the same database or different databases from |service|,
22
+ |aws| |s3|, and |http| or |https| data stores.
21
23
22
24
.. _adl-lookup-syntax:
23
25
@@ -26,9 +28,11 @@ Syntax
26
28
27
29
The ``$lookup``
28
30
:manual:`syntax </reference/operator/aggregation/lookup/#syntax>` is
29
- described in the MongoDB server manual. In {+data-lake-short+}, the ``from``
30
- field in ``$lookup`` has the following alternate syntax to support specifying
31
- an object containing an optional database name and a required collection name:
31
+ described in the MongoDB server manual.
32
+
33
+ In {+data-lake-short+}, the ``from`` field in ``$lookup`` has the
34
+ following alternate syntax. This allows you to specify an object that
35
+ contains an optional database name and a required collection name:
32
36
33
37
.. tabs::
34
38
@@ -46,7 +50,7 @@ an object containing an optional database name and a required collection name:
46
50
}
47
51
}
48
52
49
- .. tab:: Join Conditions and Uncorrelated Sub-queries
53
+ .. tab:: Conditions and Sub-Queries
50
54
:tabid: joincondition
51
55
52
56
.. code-block:: json
@@ -65,37 +69,38 @@ an object containing an optional database name and a required collection name:
65
69
66
70
.. list-table::
67
71
:header-rows: 1
68
- :widths: 10 10 70 10
72
+ :widths: 10 10 66 14
69
73
70
- * - Field
71
- - Type
72
- - Description
74
+ * - Field
75
+ - Type
76
+ - Description
73
77
- Necessity
74
78
75
79
* - ``db``
76
- - string
77
- - The database name.
80
+ - string
81
+ - The database name.
78
82
79
- If the database name is specified, data is read from the collection in
80
- the specified database. If you specify a database name that is different
81
- from the database upon which the command is operating, all nested
82
- :manual:`$lookup
83
- </reference/operator/aggregation/lookup/#pipe._S_lookup>` stages **must**
84
- also specify a database name.
85
-
86
- If the database name is not specified within a :manual:`$lookup
87
- </reference/operator/aggregation/lookup/#pipe._S_lookup>` stage,
88
- collections in the stage inherit the database name specified in the closest
89
- parent :manual:`$lookup </reference/operator/aggregation/lookup/#pipe._S_lookup>`
90
- stage if it exists or the database upon which the command is operating.
83
+ If you specify a database name, {+data-lake-short+} reads data
84
+ from the collection in the specified database. If you specify a
85
+ database name that differs from the database upon which the
86
+ command is operating, all nested :manual:`$lookup </reference/operator/aggregation/lookup/#pipe._S_lookup>`
87
+ stages **must** also specify this database name.
88
+
89
+ If you don't specify a database name within a :manual:`$lookup
90
+ </reference/operator/aggregation/lookup/#pipe._S_lookup>` stage,
91
+ collections in the stage inherit the database name specified in
92
+ the closest parent :manual:`$lookup </reference/operator/aggregation/lookup/#pipe._S_lookup>`
93
+ stage if it exists, or the name of the database upon which the
94
+ command is operating.
95
+
91
96
- Conditional
92
97
93
- * - ``coll``
98
+ * - ``coll``
94
99
- string
95
- - The collection name.
100
+ - The collection name.
96
101
- Required
97
102
98
- Examples
103
+ Examples
99
104
--------
100
105
101
106
Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
@@ -106,7 +111,7 @@ Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
106
111
.. tab:: sourceDB1
107
112
:tabid: sourceDB1
108
113
109
- .. code-block:: json
114
+ .. code-block:: json
110
115
111
116
db.orders.insertMany([
112
117
{ "_id" : 1, "item" : "almonds", "price" : 12, "quantity" : 2 },
@@ -117,7 +122,7 @@ Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
117
122
.. tab:: sourceDB2
118
123
:tabid: sourceDB2
119
124
120
- .. code-block:: json
125
+ .. code-block:: json
121
126
122
127
db.catalog.insertMany([
123
128
{ "_id" : 1, "sku" : "almonds", "description": "product 1" },
@@ -131,7 +136,7 @@ Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
131
136
.. tab:: sourceDB3
132
137
:tabid: sourceDB3
133
138
134
- .. code-block:: json
139
+ .. code-block:: json
135
140
136
141
db.warehouses.insertMany([
137
142
{ "_id" : 1, "stock_item" : "almonds", "warehouse": "A", "instock" : 120 },
@@ -146,7 +151,7 @@ The following examples use the :manual:`$lookup
146
151
to join documents from one collection with the documents from the collection
147
152
in the other databases.
148
153
149
- Basic Example
154
+ Basic Example
150
155
~~~~~~~~~~~~~
151
156
152
157
The following aggregation operation on the ``sourceDB1.orders`` collection joins the documents from the ``orders`` collection with the documents
0 commit comments