Skip to content

Commit a822bd2

Browse files
Merge branch 'main' into patch-3
2 parents e350abd + e601ed2 commit a822bd2

16 files changed

+54
-63
lines changed

README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
# Docusaurus Template Workshop
1+
# SQL to MongoDB Query API
22

3-
This is a template to __create new Lab documentation sites__. Contains info on how to use Docusaurus and is a good starting point.
4-
5-
### Installation, use, how to build, etc.
6-
7-
Everything is covered in the Lab itself: https://mongodb-developer.github.io/docusaurus-workshop/
8-
9-
## Contributing
10-
11-
As `main` is protected, submit a pull request to be reviewed.
12-
13-
## Docusaurus
14-
15-
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. It's available on https://mongodb-developer.github.io/docusaurus-workshop/.
16-
17-
### Disclaimer
18-
19-
Use at your own risk; not a supported MongoDB product
3+
Workshop Docs hosted at: https://sql-to-query-api-lab.github.io/sql-to-query-api-lab/docs/category/prerequisites

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/30-quick-start.mdx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,26 @@ To use work through the exercises, we need to install the official MongoDB GUI.
88

99
## Connect Compass to your Atlas cluster
1010

11-
- Insert Add connection page of Compass
11+
### 1. Click on the "Add connection" button on the home page
1212

13-
## Select the library database
13+
![](/img/add-connection-compass.png)
1414

15-
- Insert databases list
15+
### 2. Paste your connection string after updating your password and click on the "Save and Connect" button
16+
17+
![](/img/enter-connection-uri-compass.png)
18+
19+
### 3. Select the library database
20+
21+
![](/img/select-db-collection-compass.png)
22+
23+
### 4. Click on the "Open MongoDB shell" button
24+
25+
![](/img/open-shell-compass.png)
26+
27+
### 5. Switch to the library database in the shell
28+
29+
Once the shell is loaded, execute: `use library` to ensure you are in the correct database.
30+
31+
![](/img/use-library-compass.png)
32+
33+
That's it for the setup, let's get our hands dirty!

docs/40-CRUD/1-WHERE.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Now, translate the following into a MongoDB Query.
115115
<summary>Answer</summary>
116116
<div>
117117
```js
118-
db.books.find({ genre: "Science", pages: {$gt: 300} });
118+
db.books.find({ genres: "Science", pages: {$gt: 300} });
119119
```
120120
</div>
121121
</details>

docs/40-CRUD/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"label": "👐 CRUD operations",
2+
"label": "👐 CRUD Operations",
33
"position": 40,
44
"link": {
55
"type": "generated-index",

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

docs/summary.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ sidebar_position: 100
44

55
# 🎯 Summary
66

7-
Congratulations! Following this tutorial, you have successfully:
7+
Congratulations! Following this tutorial, you have successfully learned:
88

9-
- TBD
10-
- TBD
11-
- TBD
12-
- TBD
13-
- TBD
9+
- How to query collections in MongoDB
10+
- How to insert, update and delete documents in MongoDB
11+
- How to write aggregation pipelines in MongoDB
1412

1513
Visit the [MongoDB Developer Center](https://mongodb.com/developer/?utm_campaign=devrel&utm_source=workshop&utm_medium=cta&utm_content=sql_to_query_api&utm_term=sourabh_bagrecha) for more useful information and tutorials.

docusaurus.config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ const config = {
136136
hideable: true,
137137
},
138138
},
139-
announcementBar: {
140-
id: "feedback_form",
141-
content:
142-
'This is a demonstration that we can put a pop-up message here! Even <a target="_blank" rel="noopener noreferrer" href="#">links</a>',
143-
backgroundColor: "#fafbfc",
144-
textColor: "#091E42",
145-
isCloseable: true,
146-
},
147139
navbar: {
148140
title: `${title}`,
149141
logo: {

static/img/add-connection-compass.png

290 KB
Loading
341 KB
Loading

static/img/open-shell-compass.png

389 KB
Loading
385 KB
Loading

static/img/use-library-compass.png

106 KB
Loading

0 commit comments

Comments
 (0)