Skip to content

Commit b14d995

Browse files
committed
Add Atlas UI sections
1 parent bbedb5a commit b14d995

15 files changed

+379
-52
lines changed

docs/1-mongodb-atlas/15-prerequisites.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ description: Setting up your MongoDB Atlas account, importing Library data
66

77
To follow along you'll need:
88
- a MongoDB Atlas account
9-
- some test data, in this case this is Books, Authors and Reviews data for a Library management system.
9+
- test data. In this case, this is books, authors and reviews data for a library management system.
1010

11-
💻 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!
11+
💻 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!

docs/30-simple-queries/0-using-library-database.mdx

+21-18
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@ import TabItem from '@theme/TabItem';
55

66
## Select the library database
77

8-
💻 We'll use the `library` database. To do that, in a MongoDB shell type in:
8+
💻 We'll use the `library` database for all of the hands-on exercises in this lab.
9+
If you haven't already, import the [library data](https://mdb.link/import-library-data) into your database cluster.
910

1011
<Tabs groupId="aggregations">
11-
<TabItem value="mongosh" label="mongosh">
12+
<TabItem value="atlas" label="Atlas UI">
13+
14+
Select the correct database in the Atlas UI.
15+
16+
17+
<Screenshot src="/img/30-simple-queries/select-db.png" url="http://cloud.mongodb.com/yourcluster" alt="AtlasUI Showing the available DBs" />
18+
19+
</TabItem>
20+
<TabItem value="mongodb-shell" label="MongoDB Shell">
21+
22+
To do that, in a MongoDB shell type in:
1223

1324
```js
1425
use library
@@ -20,26 +31,12 @@ You can show all collections with
2031
show collections
2132
```
2233

23-
</TabItem>
24-
<TabItem value="atlas" label="Atlas UI">
25-
26-
Select the correct DB in the Atlas UI
27-
28-
29-
<Screenshot src="/img/30-simple-queries/select-db.png" url="http://cloud.mongodb.com/yourcluster" alt="AtlasUI Showing the available DBs" />
30-
31-
</TabItem>
32-
</Tabs>
33-
34-
35-
3634
---
3735

38-
3936
🦸‍♂️ 💻 How would you switch to a database called `orders`?
4037

4138
:::info
42-
Extra activity, do it if you have extra time or are following at home, won't be covered during the hands-on Lab
39+
Extra activity, do it if you have extra time or are following at home, won't be covered during the hands-on lab.
4340
:::
4441

4542
<details>
@@ -70,4 +67,10 @@ You can also list other databases in your MongoDB instance with
7067

7168
```js
7269
show databases
73-
```
70+
```
71+
72+
73+
</TabItem>
74+
75+
</Tabs>
76+

docs/30-simple-queries/1-empty-aggregation.mdx

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,28 @@ import TabItem from '@theme/TabItem';
88
This code is the equivalent to a `SELECT * FROM AUTHORS`. Returns a [cursor](https://www.mongodb.com/docs/manual/reference/method/js-cursor/) with all documents in the `authors` collection:
99

1010
<Tabs groupId="aggregations">
11-
<TabItem value="mongosh" label="mongosh">
1211

13-
```js
14-
db.authors.aggregate([])
15-
```
12+
<TabItem value="atlas" label="Atlas UI">
1613

17-
</TabItem>
18-
<TabItem value="atlas" label="Atlas UI">
14+
<Screenshot src="/img/30-simple-queries/atlas-aggregation.png" url="http://cloud.mongodb.com/" alt="Atlas UI showing an empty aggregation pipeline" />
1915

20-
<Screenshot src="/img/30-simple-queries/atlas-aggregation.png" url="http://cloud.mongodb.com/yourcluster" alt="AtlasUI Showing the available DBs" />
21-
22-
- Open the Aggregation tab
23-
- Select Text entry
24-
- Type in the aggregation pipeline:
16+
- Open the `Aggregation` tab.
17+
- Select `Text`.
18+
- Notice the empty array in the editor denoting an empty aggregation pipeline:
2519

2620
```js
2721
[]
2822
```
2923

3024
</TabItem>
31-
</Tabs>
3225

26+
<TabItem value="mongodb-shell" label="MongoDB Shell">
3327

28+
```js
29+
db.authors.aggregate([])
30+
```
3431

35-
We can iterate over this cursor and get more documents typing `it`.
32+
We can iterate over the returned cursor and get more documents typing `it`.
3633

3734
💻 Return all the documents in the `books` collection and iterate to get the next page of books.
3835

@@ -70,4 +67,8 @@ cursor.itcount()
7067
db.books.aggregate([]).itcount()
7168
```
7269
</div>
73-
</details>
70+
</details>
71+
72+
</TabItem>
73+
74+
</Tabs>

docs/30-simple-queries/2-match.mdx

+154-6
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,115 @@
1-
# $match
1+
import Tabs from '@theme/Tabs';
2+
import TabItem from '@theme/TabItem';
23

3-
This is the simplest one, similar to the `WHERE` SQL clause.
4+
# $match
45

5-
Say we want all the books from 2010. We'll write:
6+
The $match operator is used in conjunction with the aggregation framework to filter documents in a collection. It takes a document as input and returns a new document containing only the documents that match the specified criteria. The syntax for the $match operator is as follows:
67

78
```js
8-
db.books.aggregate([{$match: {year: 2010}}])
9+
{ $match: { <expression>: <value> } }
910
```
1011

12+
## Expressions
13+
14+
The `<expression>` portion of the $match operator can be any valid MongoDB expression. This includes :
15+
16+
* Comparison operators: `eq`, `neq`, `gte`, `lte`, `gt`, `lt`, `in`, `nin`, `exists`
17+
* Regular expressions: regex
18+
* Logical operators: and, or, not
19+
* Subdocuments and arrays: `{ field: <value> }, [ <item>, <item>, ... ]`
20+
21+
## Matching book documents
22+
23+
<Tabs groupId="aggregations-year">
24+
<TabItem value="atlas" label="Atlas UI">
25+
26+
First, make sure you select the `books` collection in the Atlas UI.
27+
<Screenshot src="/img/30-simple-queries/select-books-collection.png" url="http://cloud.mongodb.com/" alt="Atlas UI database deployment with the books collection highlighted." />
28+
29+
Then, navigate to the `Aggregation` tab and click `Add Stage`.
30+
<Screenshot src="/img/30-simple-queries/new-aggregation.png" url="http://cloud.mongodb.com/" alt="Atlas UI database deployment with aggregation tab highlighted." />
31+
32+
Say we want all the books from the year 2010. We can add a `$match` stage to filter the documents from the books collection:
33+
34+
```js
35+
[
36+
{
37+
$match: { year: 2010 }
38+
}
39+
]
40+
```
41+
42+
<Screenshot src="/img/30-simple-queries/match-screenshot.png" url="http://cloud.mongodb.com/" alt="Atlas AI $match aggregation." />
43+
44+
</TabItem>
45+
<TabItem value="mongodb-shell" label="MongoDB Shell">
46+
Say we want all the books from 2010. We'll write:
47+
48+
```js
49+
db.books.aggregate([{$match: {year: 2010}}])
50+
```
51+
</TabItem>
52+
</Tabs>
53+
54+
1155
💻 Return all the `books` that have exactly 100 pages.
1256

1357
<details>
1458
<summary>Answer</summary>
1559
<div>
1660

61+
<Tabs groupId="aggregations-pages">
62+
<TabItem value="atlas" label="Atlas UI">
63+
```js
64+
[
65+
{
66+
$match: { pages: 100 }
67+
}
68+
]
69+
```
70+
71+
</TabItem>
72+
<TabItem value="mongodb-shell" label="MongoDB Shell">
1773
```js
1874
db.books.aggregate([{$match: {pages: 100}}])
1975
```
76+
</TabItem>
77+
</Tabs>
78+
79+
2080
</div>
2181
</details>
2282

2383
## AND
2484

25-
If we need to add more conditions using AND, we can do it using the `$and` operator.
85+
If we need to add more conditions using AND, we can do it with the `$and` operator.
2686

2787
If we want all the books with 100 pages with exactly `totalInventory` 2 we can use an `$and` operator. This takes and array of documents with all the conditions that should be true for the AND to succeed:
2888

89+
<Tabs groupId="aggregations-and">
90+
<TabItem value="atlas" label="Atlas UI">
91+
```js
92+
[
93+
{
94+
$match: {
95+
$and: [
96+
{ pages: 100 },
97+
{ totalInventory: 2 }
98+
]
99+
}
100+
}
101+
]
102+
```
103+
</TabItem>
104+
<TabItem value="mongodb-shell" label="MongoDB Shell">
29105
```js
30106
db.books.aggregate([{$match: {$and: [{pages: 100}, {totalInventory: 2}]}}])
31107
```
108+
</TabItem>
109+
</Tabs>
110+
111+
112+
32113

33114
The pseudo-code for this would be something like:
34115

@@ -44,40 +125,107 @@ IF pages == 100 AND totalInventory == 2 {
44125
<summary>Answer</summary>
45126
<div>
46127

128+
<Tabs groupId="aggregations">
129+
<TabItem value="atlas" label="Atlas UI">
130+
```js
131+
[
132+
{
133+
$match: {
134+
$and: [
135+
{ pages: 100 },
136+
{ year: 2015 }
137+
]
138+
}
139+
}
140+
]
141+
```
142+
</TabItem>
143+
<TabItem value="mongodb-shell" label="MongoDB Shell">
47144
```js
48145
db.books.aggregate([{$match: {$and: [{pages: 100}, {year: 2015}]}}])
49146
```
147+
</TabItem>
148+
</Tabs>
149+
50150
</div>
51151
</details>
52152

53-
💻 How many are they? (_hint: use `itcount()`_).
153+
💻 How many are they?
54154

55155
<details>
56156
<summary>Answer</summary>
57157
<div>
58158

159+
<Tabs groupId="aggregations">
160+
<TabItem value="atlas" label="Atlas UI">
161+
```js
162+
[
163+
{
164+
$match: {
165+
$and: [
166+
{ pages: 100 },
167+
{ year: 2015 }
168+
]
169+
}
170+
},
171+
{
172+
$count: "books_count"
173+
}
174+
]
175+
```
176+
</TabItem>
177+
<TabItem value="mongodb-shell" label="MongoDB Shell">
59178
```js
60179
db.books.aggregate([{$match: {$and: [{pages: 100}, {year: 2015}]}}]).itcount()
61180
```
181+
</TabItem>
182+
</Tabs>
62183
</div>
63184
</details>
64185

65186
### Shorthand AND
66187

67188
We can do an implicit AND just passing a document with all the conditions (instead of an array of documents):
68189

190+
<Tabs groupId="aggregations-shorthand-and">
191+
<TabItem value="atlas" label="Atlas UI">
192+
```js
193+
[
194+
{
195+
$match: {pages: 100, totalInventory: 2}
196+
}
197+
]
198+
```
199+
</TabItem>
200+
<TabItem value="mongodb-shell" label="MongoDB Shell">
69201
```js
70202
db.books.aggregate([{$match: {pages: 100, totalInventory: 2}}])
71203
```
204+
</TabItem>
205+
</Tabs>
206+
72207

73208
💻 Return all the `books` from 2015 that have exactly 100 pages, using the simple $and notation
74209

75210
<details>
76211
<summary>Answer</summary>
77212
<div>
78213

214+
<Tabs groupId="aggregations-shorthand-and-exercise">
215+
<TabItem value="atlas" label="Atlas UI">
216+
```js
217+
[
218+
{
219+
$match: {pages: 100, year: 2015}
220+
}
221+
]
222+
```
223+
</TabItem>
224+
<TabItem value="mongodb-shell" label="MongoDB Shell">
79225
```js
80226
db.books.aggregate([{$match: {pages: 100, year: 2015}}])
81227
```
228+
</TabItem>
229+
</Tabs>
82230
</div>
83231
</details>

0 commit comments

Comments
 (0)