1212 :depth: 2
1313 :class: singlecol
1414
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.
2123
2224.. _adl-lookup-syntax:
2325
@@ -26,9 +28,11 @@ Syntax
2628
2729The ``$lookup``
2830: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:
3236
3337.. tabs::
3438
@@ -46,7 +50,7 @@ an object containing an optional database name and a required collection name:
4650 }
4751 }
4852
49- .. tab:: Join Conditions and Uncorrelated Sub-queries
53+ .. tab:: Conditions and Sub-Queries
5054 :tabid: joincondition
5155
5256 .. code-block:: json
@@ -65,37 +69,38 @@ an object containing an optional database name and a required collection name:
6569
6670.. list-table::
6771 :header-rows: 1
68- :widths: 10 10 70 10
72+ :widths: 10 10 66 14
6973
70- * - Field
71- - Type
72- - Description
74+ * - Field
75+ - Type
76+ - Description
7377 - Necessity
7478
7579 * - ``db``
76- - string
77- - The database name.
80+ - string
81+ - The database name.
7882
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+
9196 - Conditional
9297
93- * - ``coll``
98+ * - ``coll``
9499 - string
95- - The collection name.
100+ - The collection name.
96101 - Required
97102
98- Examples
103+ Examples
99104--------
100105
101106Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
@@ -106,7 +111,7 @@ Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
106111 .. tab:: sourceDB1
107112 :tabid: sourceDB1
108113
109- .. code-block:: json
114+ .. code-block:: json
110115
111116 db.orders.insertMany([
112117 { "_id" : 1, "item" : "almonds", "price" : 12, "quantity" : 2 },
@@ -117,7 +122,7 @@ Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
117122 .. tab:: sourceDB2
118123 :tabid: sourceDB2
119124
120- .. code-block:: json
125+ .. code-block:: json
121126
122127 db.catalog.insertMany([
123128 { "_id" : 1, "sku" : "almonds", "description": "product 1" },
@@ -131,7 +136,7 @@ Suppose there are three databases named ``sourceDB1``, ``sourceDB2``, and
131136 .. tab:: sourceDB3
132137 :tabid: sourceDB3
133138
134- .. code-block:: json
139+ .. code-block:: json
135140
136141 db.warehouses.insertMany([
137142 { "_id" : 1, "stock_item" : "almonds", "warehouse": "A", "instock" : 120 },
@@ -146,7 +151,7 @@ The following examples use the :manual:`$lookup
146151to join documents from one collection with the documents from the collection
147152in the other databases.
148153
149- Basic Example
154+ Basic Example
150155~~~~~~~~~~~~~
151156
152157The following aggregation operation on the ``sourceDB1.orders`` collection joins the documents from the ``orders`` collection with the documents
0 commit comments