Skip to content

Commit e4188e2

Browse files
Merge pull request #12 from Meg528/patch-19
Update 5-JOIN.mdx
2 parents fdf1067 + bcac748 commit e4188e2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

docs/50-aggregation/5-JOIN.mdx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,26 @@ db.authors.aggregate([
4747
]);
4848
```
4949

50+
### **Equivalent SQL query**
51+
52+
```sql
53+
SELECT author.* , books_written.*
54+
FROM authors
55+
LEFT OUTER JOIN author_books ON authors.id = author_books.author_id
56+
LEFT OUTER JOIN books as books_written ON author_books.book_id = books_written._id;
57+
```
58+
5059
:::info
5160
The result in MongoDB will have an array (`authorDetails`) instead of flat columns.
5261
:::
5362

5463
---
5564

56-
## 🔹 Handling Unwinding ($unwind)
65+
## 🔹 Handling unwinding ($unwind)
5766

5867
Since `$lookup` produces an **array**, we can flatten it using `$unwind`.
5968

60-
### Example 2: Get Only Book Titles and Single Author Name
69+
### Example 2: Get only book titles and single author name
6170

6271
```js
6372
db.authors.aggregate([
@@ -75,7 +84,7 @@ db.authors.aggregate([
7584
```
7685

7786
:::info
78-
The $lookup operation creates an array within each book document. Using $unwind then flattens this array, resulting in a separate document for every single book - author pair.
87+
The $lookup operation creates an array within each book document. Using $unwind then flattens this array, resulting in a separate document for every single book-author pair.
7988
:::
8089

8190
---

0 commit comments

Comments
 (0)