Skip to content

Commit

Permalink
Merge pull request #26 from Meg528/patch-18
Browse files Browse the repository at this point in the history
Update 10-sorting.mdx
  • Loading branch information
dfreniche authored Sep 17, 2024
2 parents 3707d67 + 59ff357 commit f46aeaa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/50-counting-sorting/10-sorting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

👐 Let's get all books from 1984, sorted by number of pages. We'll only show the title, pages and authors.
👐 Let's get all books from 1984, sorted by number of pages. We'll only show the title, pages, and authors.

```js
let booksFrom1984 = {$match: {year: 1984}};
Expand All @@ -16,7 +16,7 @@ db.books.aggregate([
]);
```

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.
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.

👐 We can sort the other way around:

Expand Down Expand Up @@ -52,4 +52,4 @@ db.books.aggregate([
]);
```
</div>
</details>
</details>

0 comments on commit f46aeaa

Please sign in to comment.