You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/60-lookups/1-lookups.mdx
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# 👐 Lookups AKA Left Outer Join
1
+
# 👐 Lookups, AKA Left Outer Join
2
2
3
-
Using Documents we usually model 1:1, 1:many relationships embedding documents inside other documents, even using arrays for that. For instance an Author can have many aliases, and they live inside an array in the `authors` collection.
3
+
Using documents, we usually model 1:1 and 1:many relationships by embedding documents inside other documents, and even using arrays. For instance, an author can have many aliases, and they live inside an array in the `authors` collection.
4
4
5
-
But other times we need to use references to those documents instead of embedding them. For instance an author has an array of the books she has written, but instead of moving the book documents inside an array inside author (which will be tricky for books with multiple authors) we embed the books `_id` instead.
5
+
But other times, we need to use references to those documents instead of embedding them. For instance, an author has an array of the books they have written, but instead of moving the book documents inside an array inside author (which will be tricky for books with multiple authors), we embed the books `_id` instead.
6
6
7
-
So how can we get the authors and all the books she has written, embedded in the array? Using `$lookup`, that will do a Left Outer Join and return author docs containing book docs inside.
7
+
So how can we get the author and all the books they have written embedded in the array? By using `$lookup`! That will do a left outer join and return author docs containing book docs inside.
8
8
9
9
👐 Run this aggregation and look at the results:
10
10
@@ -37,7 +37,7 @@ The syntax for this version of `$lookup` is:
37
37
38
38
## Lookups from a previous stage
39
39
40
-
We can do a $lookup on the result of another pipeline, not only joining with a collection. For instance, we want to remove some noise from the books before joining, so we use `$project` to exclude a couple arrays.
40
+
We can do a $lookup on the result of another pipeline, not only joining with a collection. For instance, we want to remove some noise from the books before joining, so we use `$project` to exclude a couple of arrays.
41
41
42
42
```js
43
43
db.authors.aggregate([
@@ -54,7 +54,7 @@ db.authors.aggregate([
54
54
])
55
55
```
56
56
57
-
The nice part is that we can extract that pipeline and test it / tweak it.
57
+
The nice part is that we can extract that pipeline and test it/tweak it.
0 commit comments