Skip to content

Commit 8e9164b

Browse files
Merge branch 'main' into patch-1
2 parents 1eb45df + 7b30805 commit 8e9164b

22 files changed

+153
-150
lines changed

README.md

+2-18
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ 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-
- A MongoDB Atlas cluster.
10-
- Test data. In this case, this is book, author, and review data for a library management system.
119

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!
10+
- A free MongoDB Atlas Cluster
11+
- Sample library data
12+
13+
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

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
# 👐 Quick Start
22

3-
For the impatient AKA all of us
3+
For the impatient, AKA all of us:
44

55
## Install Compass
66

7-
To use work through the exercises, we need to install the official MongoDB GUI: [Download and Install Compass](https://www.mongodb.com/try/download/compass)
7+
To use work through the exercises, we need to install the official MongoDB GUI. [Download and install Compass](https://www.mongodb.com/try/download/compass).
88

9-
## Connect compass to your Atlas cluster
9+
## 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

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# 👐 WHERE → .find()
22

3-
Similar to SQL's `WHERE` clause, the `.find()` method in MongoDB retrieves documents from a collection that match a specified query.
3+
Similar to SQL's `WHERE` clause, the `.find()` method in MongoDB retrieves documents from a collection that matches a specified query.
44

55
## Syntax
66

77
```js
88
db.collection.find({ <query> })
99
```
1010

11-
- `<query>`: Specifies conditions to filter documents.
11+
- `<query>`: Specifies conditions to filter documents
1212

1313
## Example: Find all books from 2020
1414

1515
```js
1616
db.books.find({ year: 2020 });
1717
```
1818

19-
### Equivalent SQL Query
19+
### Equivalent SQL query
2020

2121
```sql
2222
SELECT * FROM books WHERE year = 2020;
@@ -26,24 +26,24 @@ SELECT * FROM books WHERE year = 2020;
2626

2727
The `find()` method takes a document as its first argument. This document specifies the filter criteria. You can use a variety of expressions within the filter document:
2828

29-
- **Comparison Operators:** `$eq` (equals), `$ne` (not equals), `$gt` (greater than), `$lt` (less than), `$gte` (greater than or equals), `$lte` (less than or equals), `$in` (in an array), `$nin` (not in an array).
30-
- **Logical Operators:** `$and`, `$or`, `$not`.
31-
- **Element Operators:** `$exists` (check for field existence), `$type` (check data type).
32-
- **Evaluation Operators:** `$regex` (regular expression matching), `$where` (JavaScript code execution).
33-
- **Geo-spatial Operators:** For location-based queries.
34-
- **Array Operators:** For querying arrays.
29+
- **Comparison operators:** `$eq` (equals), `$ne` (not equals), `$gt` (greater than), `$lt` (less than), `$gte` (greater than or equals), `$lte` (less than or equals), `$in` (in an array), `$nin` (not in an array)
30+
- **Logical operators:** `$and`, `$or`, `$not`
31+
- **Element operators:** `$exists` (check for field existence), `$type` (check data type)
32+
- **Evaluation operators:** `$regex` (regular expression matching), `$where` (JavaScript code execution)
33+
- **Geo-spatial operators:** For location-based queries
34+
- **Array operators:** For querying arrays
3535

3636
Now, let's utilize a few MongoDB operators and create more sophisticated queries:
3737

38-
### $or and $gt operator
38+
### $or and $gt operators
3939

40-
Suppose, we want to get all the books written in 2010 OR has more than 200 pages.
40+
Suppose we want to get all the books written in 2010 OR books that have more than 200 pages.
4141

4242
```sql
4343
SELECT * FROM books WHERE year = 2010 OR pages > 200
4444
```
4545

46-
Equivalent MongoDB Query:
46+
Equivalent MongoDB query:
4747

4848
```js
4949
db.books.find({
@@ -56,7 +56,7 @@ db.books.find({
5656

5757
### $and operator
5858

59-
This time, instead of OR let's query using AND:
59+
This time, instead of OR, let's query using AND:
6060

6161
```sql
6262
SELECT * FROM books WHERE year = 2010 AND pages > 200
@@ -75,17 +75,17 @@ db.books.find({
7575

7676
### Shorthand $and
7777

78-
When we are querying on 2 different fields and want to utilize $and, we can do so by passing a document with all the conditions like this:
78+
When we are querying on two different fields and want to utilize $and, we can do so by passing a document with all the conditions, like this:
7979

8080
```js
8181
db.books.find({ year: 2010, pages: { $gt: 200 } });
8282
```
8383

84-
As you can see, we don't have to pass an Array of conditions, MongoDB implicitly considers this as $and.
84+
As you can see, we don't have to pass an array of conditions. MongoDB implicitly considers this as $and.
8585

8686
## 👐 Challenge
8787

88-
Now, translate the following into a MongoDB Query.
88+
Now, translate the following into a MongoDB query.
8989

9090
#### 1. Find all books where `totalInventory` is exactly 5.
9191

@@ -109,13 +109,13 @@ Now, translate the following into a MongoDB Query.
109109
</div>
110110
</details>
111111

112-
#### 3. Find books in the "Science" genre that has more than 300 pages.
112+
#### 3. Find books in the "Science" genre that have more than 300 pages.
113113

114114
<details>
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/2-SELECT.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In SQL, the `SELECT` statement allows us to specify which columns to retrieve fr
88
db.collection.find({ <query> }, { projection })
99
```
1010

11-
## **Projection Basics**
11+
## **Projection basics**
1212

1313
- By default, MongoDB returns all fields in a document.
1414
- Use projection to **include (1)** or **exclude (0)** specific fields.
@@ -21,7 +21,7 @@ db.collection.find({ <query> }, { projection })
2121
db.books.find({}, { title: 1, authors: 1, _id: 0 });
2222
```
2323

24-
**Equivalent SQL Query:**
24+
**Equivalent SQL query:**
2525

2626
```sql
2727
SELECT title, authors FROM books;
@@ -40,7 +40,7 @@ Here:
4040
db.books.find({}, { reviews: 0 });
4141
```
4242

43-
**Equivalent SQL Query:**
43+
**Equivalent SQL query:**
4444

4545
```sql
4646
SELECT title, authors, genres, totalInventory, available FROM books;
@@ -52,13 +52,13 @@ Here:
5252

5353
---
5454

55-
## **Example 3: Using Projection along with a Query**
55+
## **Example 3: Using projection along with a query**
5656

5757
```js
5858
db.books.find({ genres: "Science" }, { title: 1, totalInventory: 1, _id: 0 });
5959
```
6060

61-
**Equivalent SQL Query:**
61+
**Equivalent SQL query:**
6262

6363
```sql
6464
SELECT title, totalInventory FROM books WHERE genres='Science';

docs/40-CRUD/3-ORDER-LIMIT.mdx

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ In SQL, we use `ORDER BY` to sort query results and `LIMIT` to restrict the numb
1010
- `{ field: -1 }`**Descending order** (Z → A, largest to smallest)
1111
- You can sort by multiple fields, just like SQL.
1212

13-
## **Limiting Results**
13+
## **Limiting results**
1414

1515
- `.limit(n)` restricts the number of documents returned.
1616
- Used together with `.sort()`, it helps fetch the **top N** results.
1717

1818
---
1919

20-
### 1: Top 5 Books with the Highest Inventory
20+
### 1: Top 5 books with the highest inventory
2121

2222
```js
2323
db.books.find().sort({ totalInventory: -1 }).limit(5);
2424
```
2525

26-
**Equivalent SQL Query:**
26+
**Equivalent SQL query:**
2727

2828
```sql
2929
SELECT * FROM books ORDER BY totalInventory DESC LIMIT 5;
@@ -33,7 +33,7 @@ This fetches the **5 books with the highest stock**.
3333

3434
---
3535

36-
### 2: Get the title of top 10 Fiction Books by highest page count
36+
### 2: Get the title of top 10 fiction books by highest page count
3737

3838
```js
3939
db.books
@@ -44,11 +44,11 @@ db.books
4444

4545
:::info
4646

47-
Along with the title, we fetched pages as well to ensure that we are getting the right results.
47+
Along with the title, we fetched pages, as well, to ensure that we are getting the right results.
4848

4949
:::
5050

51-
**Equivalent SQL Query:**
51+
**Equivalent SQL query:**
5252

5353
```sql
5454
SELECT title, pages FROM books WHERE genres='Fiction' ORDER BY pages DESC LIMIT 10;

docs/40-CRUD/4-INSERT-DELETE.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
MongoDB provides two methods for inserting documents into a collection:
44

5-
- `.insertOne()`: Inserts a single document.
6-
- `.insertMany()`: Inserts multiple documents at once.
5+
- `.insertOne()`: Inserts a single document
6+
- `.insertMany()`: Inserts multiple documents at once
77

8-
And just like insert MongoDB provides:
8+
And just like insert, MongoDB provides:
99

1010
- `.deleteOne()`: Deletes the first matching document.
1111
- `.deleteMany()`: Deletes all matching documents.
@@ -21,7 +21,7 @@ db.reviews.insertOne({
2121
});
2222
```
2323

24-
### Equivalent SQL Query
24+
### Equivalent SQL query
2525

2626
```sql
2727
INSERT INTO reviews (text, rating, name, bookId)
@@ -55,7 +55,7 @@ db.reviews.deleteOne({
5555
});
5656
```
5757

58-
### Equivalent SQL Query
58+
### Equivalent SQL query
5959

6060
```sql
6161
DELETE FROM reviews WHERE bookId = '0786222727';

docs/40-CRUD/5-UPDATE.mdx

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ db.collection.updateOne(
1515
)
1616
```
1717

18-
- `<query>`: Specifies which document to update.
18+
- `<query>`: Specifies which document to update
1919

2020
- `<update operation>`: Defines modifications using update operators like $set, $inc, etc.
2121

22-
- `<options>`: (Optional) Allows additional configurations like upsert: true.
22+
- `<options>`: (Optional) Allows additional configurations like upsert: true
2323

2424
## Example: Update a book
2525

@@ -30,15 +30,15 @@ db.reviews.updateOne(
3030
);
3131
```
3232

33-
### Equivalent SQL Query
33+
### Equivalent SQL query
3434

3535
```sql
3636
UPDATE reviews SET rating = 5 WHERE bookId = '0312979509';
3737
```
3838

3939
## Upsert option
4040

41-
Let's say, we want to update a review in our database from "John" for the book "0312979509" by rating it 5 stars.
41+
Let's say we want to update a review in our database from "John" for the book "0312979509" by rating it 5 stars.
4242

4343
```js
4444
db.reviews.updateOne(
@@ -47,9 +47,9 @@ db.reviews.updateOne(
4747
);
4848
```
4949

50-
Suppose "John" had never posted a review for this book before, the above query won't really do anything.
50+
Suppose "John" had never posted a review for this book before. The above query won't really do anything.
5151
In some cases, we may want to store a fresh new review based on the condition and updates mentioned in query.
52-
To handle such scenarios in MongoDB, we don't have to write additional application code to achieve this, all we have to do is- utilize the `upsert` option.
52+
To handle such scenarios in MongoDB, we don't have to write additional application code to achieve this. All we have to do is utilize the `upsert` option.
5353

5454
```js
5555
db.reviews.updateOne(
@@ -61,7 +61,7 @@ db.reviews.updateOne(
6161

6262
:::info
6363

64-
Executing the above command, will insert a fresh new document in the collection like this:
64+
Executing the above command will insert a fresh new document in the collection, like this:
6565

6666
```js
6767
{

docs/40-CRUD/_category_.json

+1-1
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",

0 commit comments

Comments
 (0)