Skip to content

Commit 357e739

Browse files
fixed typos and sequence
1 parent 0bdffba commit 357e739

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

docs/20-prerequisites/20-prerequisite.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Setting up your MongoDB Atlas account, importing Library data
66

77
To follow along, you'll need to complete the first two labs of the MongoDB for RDBMS professionals. Which will help you in getting:
88

9-
- MongoDB Atlas Cluster
10-
- Test data. In this case, this is book, author, and review data for a library management system.
9+
- A free MongoDB Atlas Cluster
10+
- Sample data
1111

12-
👐 To get both, open the [intro lab](https://mongodb-developer.github.io/intro-lab/docs/intro) and follow it (only takes 10-15 mins) to get your database ready. Return here when finished!
12+
To get both, open the [intro lab](https://mongodb-developer.github.io/intro-lab/docs/intro) and follow it (only takes 10-15 mins) to get your database ready. Return here when finished!

docs/50-aggregation/3-sort-limit.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ SELECT * FROM books ORDER BY timestamp DESC LIMIT 5;
7777
```js
7878
db.books.aggregate([
7979
{
80-
$match: { year: {$lt: 2010}}
80+
$match: { year: {$gt: 2010}}
8181
},
8282
{
8383
$project: {

docs/50-aggregation/4-group.mdx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,52 +91,59 @@ db.books.aggregate([
9191

9292
---
9393

94-
## 👐 Example 3: Find the Average Book Rating of all books
94+
## 👐 Example 3: Find the total number of pages published every year.
9595

9696
### **MongoDB Query**
9797

9898
```js
99-
db.reviews.aggregate([
100-
{ $group: { _id: "$bookId", avgRating: { $avg: "$rating" } } },
99+
db.books.aggregate([
100+
{
101+
$group: {
102+
_id: "$year",
103+
totalPages: { $sum: "$pages" },
104+
},
105+
},
101106
]);
102107
```
103108

104109
### Equivalent SQL Query
105110

106111
```sql
107-
SELECT bookId, AVG(rating) AS avgRating
108-
FROM reviews
109-
GROUP BY bookId;
112+
SELECT year, SUM(rating) AS totalPages
113+
FROM books
114+
GROUP BY year;
110115
```
111116

112117
### Sample Output
113118

114119
```json
115120
[
116-
{ "_id": "1885865171", "avgRating": 4.2 },
117-
{ "_id": "0738701688", "avgRating": 4.33 },
118-
{ "_id": "0747545448", "avgRating": 5 }
121+
{ "_id": 1955, "totalPages": 664 },
122+
{ "_id": 1952, "totalPages": 416 },
123+
{ "_id": 1899, "totalPages": 128 }
124+
...
119125
]
120126
```
121127

122128
---
123129

124130
## 👐 Challenge
125131

126-
### 👐 1. Find the total number of pages published every year.
132+
### 👐 1. Find the Average Book Rating of all books
127133

128134
<details>
129135
<summary>Answer</summary>
130136
```js
131-
db.books.aggregate([
137+
db.reviews.aggregate([
132138
{
133139
$group: {
134-
_id: "$year",
135-
totalPages: { $sum: "$pages" }
140+
_id: "$bookId",
141+
avgRating: { $avg: "$rating" }
136142
}
137143
},
138144
]);
139145
```
146+
140147
</details>
141148

142149
### 👐 2. Find users with the most number of reviews. Hint: Use the `name` field in the reviews collection.

docs/50-aggregation/5-JOIN.mdx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ db.authors.aggregate([
4747
]);
4848
```
4949

50-
### **Equivalent SQL Query**
51-
52-
```sql
53-
SELECT books.*, authors.*
54-
FROM authors
55-
LEFT JOIN books ON authors._id = books.author_id;
56-
```
57-
5850
:::info
5951
The result in MongoDB will have an array (`authorDetails`) instead of flat columns.
6052
:::

docs/50-aggregation/7-CREATE-VIEW.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 👐 $merge
1+
# 🦸 $merge
22

33
In MongoDB, the **$merge** stage allows you to **write the results of an aggregation pipeline into a new or existing collection**. This is similar to the concept of "INSERT INTO ... SELECT" or "MERGE INTO" in SQL databases.
44

0 commit comments

Comments
 (0)