Skip to content

Commit 0ac93ed

Browse files
committed
Fixed examples for new data
1 parent e7684e8 commit 0ac93ed

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

docs/50-counting-sorting/10-sorting.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
We can sort our results using the `$sort` stage. We need to sort on a field, being 1 ascending and -1 descending order.
44

5-
Let's get all books from 1984, sorted by number of pages. We'll only show the title, pages and authors.
5+
💻 Let's get all books from 1984, sorted by number of pages. We'll only show the title, pages and authors.
66

77
```js
88
let booksFrom1984 = {$match: {year: 1984}};
@@ -16,8 +16,9 @@ db.books.aggregate([
1616
]);
1717
```
1818

19-
As we can see, we don't get any `pages` info as these documents don't have that information, hence is `null` and gets sorted as less than any number. We can sort the other way around:
19+
As we can see, books with no `pages` info appear first. These documents don't have that information, hence `pages` is `null` and gets sorted as less than any number.
2020

21+
💻 We can sort the other way around:
2122

2223
```js
2324
let booksFrom1984 = {$match: {year: 1984}};

docs/60-lookups/1-lookups.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ db.authors.aggregate([
5757
The nice part is that we can extract that pipeline and test it / tweak it.
5858

5959
```js
60-
let booksFrom1996 = [
61-
{$match: {year: 1996}},
60+
let justShowTitleSynopsis = [
6261
{$project: {title: 1, synopsis: 1}},
6362
]
6463

@@ -68,7 +67,7 @@ db.authors.aggregate([
6867
localField: "books",
6968
foreignField: "_id",
7069
pipeline:
71-
booksFrom1996,
70+
justShowTitleSynopsis,
7271
as: "booksWritten"
7372
}
7473
}

docs/60-lookups/2-advanced-lookups.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ db.books.aggregate([
1616
// as a book can have many authors, we get one doc per book's author
1717
{$unwind: "$authors"},
1818
// remove some noisy fields
19-
{$project: {vectorizedSynopsis: 0, attributes: 0, reviews: 0}}
19+
{$project: {attributes: 0, reviews: 0}}
2020
])
2121
```
2222
- now, we need to get the authors'information. For that, we'll use `$lookup`, linking the `_id` in the `authors` collection with the `_id` we have in each book's `authors` array. But as we can see here, these have a different type: the ones inside our array are Strings, while the `author` collection `_id` are `ObjectId`.
@@ -37,7 +37,7 @@ db.books.aggregate([
3737
// convert it to an objectId
3838
{"$set":{"authorId":{"$toObjectId":"$authors._id"}}},
3939
// remove some noisy fields
40-
{$project: {vectorizedSynopsis: 0, attributes: 0, reviews: 0}}
40+
{$project: {attributes: 0, reviews: 0}}
4141
])
4242
```
4343

@@ -60,7 +60,7 @@ db.books.aggregate([
6060
}
6161
},
6262
// remove some noisy fields
63-
{$project: {vectorizedSynopsis: 0, attributes: 0, reviews: 0}}
63+
{$project: {attributes: 0, reviews: 0}}
6464
])
6565
```
6666

0 commit comments

Comments
 (0)