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
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
Copy file name to clipboardExpand all lines: docs/20-prerequisites/20-prerequisite.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ description: Setting up your MongoDB Atlas account, importing Library data
6
6
7
7
To follow along, you'll need to complete the first two labs of the MongoDB for RDBMS professionals. Which will help you in getting:
8
8
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
11
11
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!
Copy file name to clipboardExpand all lines: docs/40-CRUD/1-WHERE.mdx
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,22 @@
1
1
# 👐 WHERE → .find()
2
2
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.
4
4
5
5
## Syntax
6
6
7
7
```js
8
8
db.collection.find({ <query> })
9
9
```
10
10
11
-
-`<query>`: Specifies conditions to filter documents.
11
+
-`<query>`: Specifies conditions to filter documents
12
12
13
13
## Example: Find all books from 2020
14
14
15
15
```js
16
16
db.books.find({ year:2020 });
17
17
```
18
18
19
-
### Equivalent SQL Query
19
+
### Equivalent SQL query
20
20
21
21
```sql
22
22
SELECT*FROM books WHERE year =2020;
@@ -26,24 +26,24 @@ SELECT * FROM books WHERE year = 2020;
26
26
27
27
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:
28
28
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).
-**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)
Copy file name to clipboardExpand all lines: docs/50-aggregation/5-JOIN.mdx
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,12 +47,13 @@ db.authors.aggregate([
47
47
]);
48
48
```
49
49
50
-
### **Equivalent SQL Query**
50
+
### **Equivalent SQL query**
51
51
52
52
```sql
53
-
SELECTbooks.*, authors.*
53
+
SELECTauthor.* , books_written.*
54
54
FROM authors
55
-
LEFT JOIN books ONauthors._id=books.author_id;
55
+
LEFT OUTER JOIN author_books ONauthors.id=author_books.author_id
56
+
LEFT OUTER JOIN books as books_written ONauthor_books.book_id=books_written._id;
56
57
```
57
58
58
59
:::info
@@ -61,11 +62,11 @@ The result in MongoDB will have an array (`authorDetails`) instead of flat colum
61
62
62
63
---
63
64
64
-
## 🔹 Handling Unwinding ($unwind)
65
+
## 🔹 Handling unwinding ($unwind)
65
66
66
67
Since `$lookup` produces an **array**, we can flatten it using `$unwind`.
67
68
68
-
### Example 2: Get Only Book Titles and Single Author Name
69
+
### Example 2: Get only book titles and single author name
69
70
70
71
```js
71
72
db.authors.aggregate([
@@ -83,7 +84,7 @@ db.authors.aggregate([
83
84
```
84
85
85
86
:::info
86
-
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.
Copy file name to clipboardExpand all lines: docs/50-aggregation/7-CREATE-VIEW.mdx
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# 👐 $merge
1
+
# 🦸 $merge
2
2
3
3
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.
4
4
@@ -8,12 +8,12 @@ In MongoDB, the **$merge** stage allows you to **write the results of an aggrega
8
8
9
9
The `$merge` stage enables you to store aggregation results into a different collection. If the target collection doesn’t exist, MongoDB will create it automatically.
10
10
11
-
### **Key Features:**
11
+
### **Key features:**
12
12
13
-
✔️ Inserts new documents if they don’t exist.
14
-
✔️ Updates existing documents based on `_id` or a specified field.
15
-
✔️ Can replace, merge, or discard duplicate records.
16
-
✔️ Useful for **ETL workflows, reporting tables, and maintaining summary data.**
13
+
✔️ Inserts new documents if they don’t exist
14
+
✔️ Updates existing documents based on `_id` or a specified field
15
+
✔️ Can replace, merge, or discard duplicate records
16
+
✔️ Useful for **ETL workflows, reporting tables, and maintaining summary data**
17
17
18
18
---
19
19
@@ -42,7 +42,7 @@ The `$merge` stage enables you to store aggregation results into a different col
42
42
43
43
---
44
44
45
-
## **🔹 Example 1: Creating a Summary Collection**
45
+
## **🔹 Example 1: Creating a summary collection**
46
46
47
47
👉 Suppose we want to generate a collection that contains the **total number of books per genre**.
Copy file name to clipboardExpand all lines: docs/summary.mdx
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,10 @@ sidebar_position: 100
4
4
5
5
# 🎯 Summary
6
6
7
-
Congratulations! Following this tutorial, you have successfully:
7
+
Congratulations! Following this tutorial, you have successfully learned:
8
8
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
14
12
15
13
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.
0 commit comments