Skip to content

Commit e7684e8

Browse files
committed
Fixed examples for new data
1 parent 21044b1 commit e7684e8

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

docs/30-simple-queries/8-aggregation-options.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ Extra activity, do it if you have extra time or are following at home, won't be
77

88
We can pass a document to `aggregate` with some options
99

10+
```js
1011
let options = {
1112
maxTimeMS: 100
1213
};
1314

1415
db.authors.aggregate([], options);
15-
16+
```
1617

1718
💻 Have a look at the [different options you can pass to the aggregate method](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate).
1819

docs/40-using-arrays/1-simple-match-array.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ I got this one (can change depending on the data source you imported)
1919
name: 'Richard Bruce Wright',
2020
sanitizedName: 'richardbrucewright',
2121
books: [
22-
'0002005018',
23-
'0771597185'
22+
'0002005018'
2423
],
2524
aliases: [
2625
'Wright, Richard Bruce'
@@ -36,16 +35,16 @@ db.authors.aggregate([
3635
])
3736
```
3837

39-
💻 Get book's author name for ISBN `9780439139595`:
38+
💻 Get book's author name for ISBN `0395623650`:
4039

4140
<details>
4241
<summary>Answer</summary>
4342
<div>
4443

4544
```js
46-
db.authors.aggregate([{$match: {books: "9780439139595"}}])
45+
db.authors.aggregate([{$match: {books: "0395623650"}}])
4746

48-
> name: 'J.K. Rowling',
47+
> name: 'Juan Ramón Jiménez',
4948
```
5049
</div>
5150
</details>
@@ -64,7 +63,7 @@ db.authors.aggregate([
6463
])
6564
```
6665

67-
💻 Who wrote the most books?
66+
💻 Who wrote the most books? (we can sort using `{ $sort: {"bookCount": -1}}`)
6867

6968
<details>
7069
<summary>Answer</summary>
@@ -83,7 +82,6 @@ let orderByNumberOfBooksDesc = { $sort: {"bookCount": -1}}
8382
let getOne = {$limit: 1}
8483

8584
db.authors.aggregate([
86-
8785
addNumberBooks,
8886
orderByNumberOfBooksDesc,
8987
getOne,

docs/40-using-arrays/2-search-inside-objects-in-arrays.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ db.books.aggregate([
5555

5656
Here we're getting a copy of each book for each object inside the `$attributes` array. This "flattens" the array and returns many copies of the same documents, one for each different attribute that we have which will be different for each of these generated docs.
5757

58-
To understand `$unwind`, run this aggregation
58+
To better understand `$unwind`, run this aggregation
5959

60+
```js
6061
db.books.aggregate([
61-
{ $match: {_id: "0002158698"} },
62-
{ $unwind : "$genres" },
63-
{ $project: {vectorizedSynopsis: 0, attributes: 0}}
62+
{ $match: {_id: "0395623650"} },
63+
{ $unwind : "$attributes" },
6464
]);
65+
```
66+
67+
You should get one document per attribute of the original book.

docs/50-counting-sorting/1-counting-documents.mdx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
# $count
22

3-
How can we be sure that this pipeline is returning exactly 10 books?
3+
How can we be sure that this pipeline is returning exactly 2 books?
44

55
```js
6-
let booksFrom1991With150pages = {$match: {year: 1991, pages: 150}};
6+
let moreThan150pages = {pages: {$gte: 150}}
7+
let booksFrom1985WithMoreThan150pages = {$match: {$and: [{year: 1985}, moreThan150pages]}};
78
let showOnlyTheseFields = {$project: {_id: 0, title: 1, year: 1, totalInventory: 1, available: 1}};
8-
let getJust15books = {$limit: 10};
9+
let getJust15books = {$limit: 15};
910

1011
db.books.aggregate([
11-
booksFrom1991With150pages,
12+
booksFrom1985With150pages,
1213
showOnlyTheseFields,
13-
getJust15books
14+
getJust15books,
1415
]);
1516
```
1617

1718
Counting the books! Let's add a new stage to the pipeline to count those books:
1819

1920
```js
20-
let booksFrom1991With150pages = {$match: {year: 1991, pages: 150}};
21+
let moreThan150pages = {pages: {$gte: 150}}
22+
let booksFrom1985WithMoreThan150pages = {$match: {$and: [{year: 1985}, moreThan150pages]}};
2123
let showOnlyTheseFields = {$project: {_id: 0, title: 1, year: 1, totalInventory: 1, available: 1}};
22-
let getJust15books = {$limit: 10};
24+
let getJust15books = {$limit: 15};
2325
let count = {$count: "totalBooks"}
2426

2527
db.books.aggregate([
26-
booksFrom1991With150pages,
28+
booksFrom1985With150pages,
2729
showOnlyTheseFields,
2830
getJust15books,
2931
count,
@@ -34,7 +36,7 @@ Here, `$count` will count the resulting docs and will return a document with jus
3436

3537
```js
3638
{
37-
totalBooks: 10
39+
totalBooks: 2
3840
}
3941
```
4042

@@ -53,16 +55,17 @@ db.authors.aggregate([{$count: "authorCount"}])
5355

5456
## The order of stages is important
5557

56-
If we count after the `$match` stage, the document we're passing to the next steps contains only the `totalBooks` field. So the `$project` will return an empty document.
58+
If we count after the `$match` stage, the document we're passing to the next steps contains only the `totalBooks` field. So the `$project` stage will return an empty document.
5759

5860
```js
59-
let booksFrom1991With150pages = {$match: {year: 1991, pages: 150}};
61+
let moreThan150pages = {pages: {$gte: 150}}
62+
let booksFrom1985WithMoreThan150pages = {$match: {$and: [{year: 1985}, moreThan150pages]}};
6063
let showOnlyTheseFields = {$project: {_id: 0, title: 1, year: 1, totalInventory: 1, available: 1}};
61-
let getJust15books = {$limit: 10};
64+
let getJust15books = {$limit: 15};
6265
let count = {$count: "totalBooks"}
6366

6467
db.books.aggregate([
65-
booksFrom1991With150pages,
68+
booksFrom1985With150pages,
6669
count,
6770
showOnlyTheseFields,
6871
getJust15books,

0 commit comments

Comments
 (0)