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
Copy file name to clipboardExpand all lines: docs/50-aggregation/2-match-project.mdx
+8-8
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# 👐 $match and $project
2
2
3
-
MongoDB’s **Aggregation Framework** allows for powerful data transformations and analysis. The **$match**, **$project** &**$sort** stages are fundamental building blocks of an aggregation pipeline.
3
+
MongoDB’s **Aggregation Framework** allows for powerful data transformations and analysis. The **$match**, **$project**, and**$sort** stages are fundamental building blocks of an aggregation pipeline.
4
4
5
5
---
6
6
7
-
## **🔹 $match → Filtering Data**
7
+
## **🔹 $match → Filtering data**
8
8
9
9
Just like `.find()` based on the query mentioned, the `$match` stage filters documents from the collection.
10
10
@@ -14,7 +14,7 @@ Just like `.find()` based on the query mentioned, the `$match` stage filters doc
14
14
{ $match: { <query> } }
15
15
```
16
16
17
-
### Example: Get All the Books that were published after the year 2010
17
+
### Example: Get all the books that were published after the year 2010
18
18
19
19
```js
20
20
db.books.aggregate([
@@ -30,7 +30,7 @@ Place `$match` as early as possible in the pipeline to reduce the number of docu
30
30
31
31
---
32
32
33
-
## **🔹 $project → Selecting Fields**
33
+
## **🔹 $project → Selecting fields**
34
34
35
35
- The `$project` stage controls which fields are included in the output.
36
36
- It can also be used for adding computed fields to the results.
@@ -50,7 +50,7 @@ Place `$match` as early as possible in the pipeline to reduce the number of docu
50
50
-`1`: Include the field
51
51
-`0`: Exclude the field
52
52
53
-
### Example: Get all the books published after the year 2010, the output should only include the title, year and page count of the book.
53
+
### Example: Get all the books published after the year 2010. The output should only include the title, year, and page count of the book.
54
54
55
55
```js
56
56
db.books.aggregate([
@@ -68,13 +68,13 @@ db.books.aggregate([
68
68
]);
69
69
```
70
70
71
-
### **Equivalent SQL Query**
71
+
### **Equivalent SQL query**
72
72
73
73
```sql
74
74
SELECT title, year, pages FROM books WHERE year>2010;
75
75
```
76
76
77
-
### **Computed Fields Example:** Along with the title & authors, also output the count of authors for every book in the database.
77
+
### **Computed fields example:** Along with the title and authors, also output the count of authors for every book in the database.
78
78
79
79
```js
80
80
db.books.aggregate([
@@ -105,7 +105,7 @@ db.books.aggregate([
105
105
</div>
106
106
</details>
107
107
108
-
### 👐 2. Find books with more than 2 available copies, return only book titles and publication year.
108
+
### 👐 2. Find books with more than 2 available copies. Return only book titles and publication year.
0 commit comments