1
00:00:02,060 --> 00:00:04,230
So time to practice what we did.

2
00:00:04,230 --> 00:00:05,840
For this, I'll first of all,

3
00:00:05,840 --> 00:00:07,600
fetch all my restaurants again

4
00:00:07,600 --> 00:00:11,003
and now I wanna leave a review for the Berlin Burgerhouse.

5
00:00:12,540 --> 00:00:17,370
For this, I'll again repeat this insert one command.

6
00:00:17,370 --> 00:00:21,513
I pressed the up key to get to this command again here.

7
00:00:22,480 --> 00:00:26,030
And now this time, it's not for the Munich Schnitzelhouse.

8
00:00:26,030 --> 00:00:29,983
Instead, it will be for this Berlin Burgerhouse.

9
00:00:31,160 --> 00:00:36,160
So I'll copy that name, copy that string here, this ID,

10
00:00:37,090 --> 00:00:41,173
and replace this ID and object ID with it.

11
00:00:42,310 --> 00:00:46,563
And I'll leave the date for convenience reasons,

12
00:00:48,250 --> 00:00:50,693
change the review text a little bit though.

13
00:00:52,030 --> 00:00:53,683
This was amazing.

14
00:00:54,840 --> 00:00:57,440
And change the rating here to five,

15
00:00:57,440 --> 00:00:59,800
and I will leave my name.

16
00:00:59,800 --> 00:01:03,160
And actually here, I was lacking a closing parenthesis

17
00:01:03,160 --> 00:01:07,233
so now I insert this and now this review was also inserted.

18
00:01:09,040 --> 00:01:11,900
So now we got two reviews,

19
00:01:11,900 --> 00:01:13,440
if we find that we got two

20
00:01:13,440 --> 00:01:16,020
restaurants and of course we could add more,

21
00:01:16,020 --> 00:01:19,020
but now I want to instead practice querying.

22
00:01:19,020 --> 00:01:21,390
And let's say we want to find all the reviews

23
00:01:21,390 --> 00:01:24,300
that have a rating greater than four.

24
00:01:24,300 --> 00:01:26,500
In this case, that would only be one review.

25
00:01:27,810 --> 00:01:28,790
To do this,

26
00:01:28,790 --> 00:01:32,020
we can execute db reviews find,

27
00:01:32,020 --> 00:01:34,760
and then pass our condition here.

28
00:01:34,760 --> 00:01:36,440
And you'll learn that here, for example,

29
00:01:36,440 --> 00:01:39,370
we can look for reviews that have a rating of five

30
00:01:39,370 --> 00:01:40,730
like this,

31
00:01:40,730 --> 00:01:43,700
but we can also do things like searching for values

32
00:01:43,700 --> 00:01:46,560
greater than four or a smaller than three

33
00:01:46,560 --> 00:01:47,910
or whatever you want to do.

34
00:01:48,830 --> 00:01:51,140
For this, instead of passing a value here,

35
00:01:51,140 --> 00:01:55,160
you pass an object and then you use the special dollar sign

36
00:01:55,160 --> 00:01:59,040
gt or lt commands here.

37
00:01:59,040 --> 00:02:02,530
There also is lte and gte,

38
00:02:02,530 --> 00:02:04,983
which stands for a greater than or equal

39
00:02:04,983 --> 00:02:09,983
or just greater than, or lower than or lower than and equal.

40
00:02:10,810 --> 00:02:13,840
So these again are reserved names,

41
00:02:13,840 --> 00:02:18,840
reserved filter conditions that you can use when filtering.

42
00:02:18,920 --> 00:02:21,960
It's important that you pass them inside of an object,

43
00:02:21,960 --> 00:02:25,800
which you pass as a value for the key where you want

44
00:02:25,800 --> 00:02:26,633
to filter.

45
00:02:27,550 --> 00:02:28,630
And then for example,

46
00:02:28,630 --> 00:02:33,340
you can search for reviews where the rating is greater

47
00:02:33,340 --> 00:02:36,270
than four by running this command.

48
00:02:36,270 --> 00:02:37,518
And of course,

49
00:02:37,518 --> 00:02:40,080
we only find one review here because the other review

50
00:02:40,080 --> 00:02:44,330
had a rating of three, which is not bigger than four.

51
00:02:44,330 --> 00:02:47,700
Now you can find a list of all these supported operators

52
00:02:47,700 --> 00:02:50,610
in the official Mongo DB documentation.

53
00:02:50,610 --> 00:02:54,070
If you search for query and projection operators,

54
00:02:54,070 --> 00:02:56,750
or you click into reference operators,

55
00:02:56,750 --> 00:02:58,640
query and projection operators,

56
00:02:58,640 --> 00:03:02,420
here you find comparison operators like gt,

57
00:03:02,420 --> 00:03:03,840
which I just showed you.

58
00:03:03,840 --> 00:03:05,710
And there are more operators,

59
00:03:05,710 --> 00:03:10,160
also for concatenating conditions and so on.

60
00:03:10,160 --> 00:03:13,810
Again, I got a full Mongo DB course where you can learn

61
00:03:13,810 --> 00:03:16,200
all about that in great depth,

62
00:03:16,200 --> 00:03:19,670
but the official docs here of course are also a great place

63
00:03:19,670 --> 00:03:22,743
to play around with that and practice these things.

64
00:03:23,600 --> 00:03:24,433
For example,

65
00:03:24,433 --> 00:03:26,980
if you would want to find all reviews that are greater

66
00:03:26,980 --> 00:03:30,550
than four and smaller than three,

67
00:03:30,550 --> 00:03:35,550
you could write this differently and write dollar sign and,

68
00:03:37,170 --> 00:03:40,830
and then a list of all the conditions that should be met.

69
00:03:40,830 --> 00:03:43,853
That's what you'll learn in the official documentation here.

70
00:03:45,590 --> 00:03:49,000
And then in there in this list, you have objects.

71
00:03:49,000 --> 00:03:52,800
So opening and closing curly braces,

72
00:03:52,800 --> 00:03:57,640
where you look for a rating gt one

73
00:03:59,380 --> 00:04:01,830
and then separated by a comma another object

74
00:04:01,830 --> 00:04:05,913
where you look for rating lt three.

75
00:04:08,000 --> 00:04:10,470
So I guess we're looking for ratings

76
00:04:10,470 --> 00:04:12,090
with a value of two here,

77
00:04:12,090 --> 00:04:13,900
but I just want to show you how you could,

78
00:04:13,900 --> 00:04:16,850
for example, also combine conditions.

79
00:04:16,850 --> 00:04:17,683
And here, of course,

80
00:04:17,683 --> 00:04:20,610
I don't find anything because we have no review

81
00:04:20,610 --> 00:04:23,110
with a rating of two in this case.

82
00:04:23,110 --> 00:04:25,040
Now this might look strange at first.

83
00:04:25,040 --> 00:04:27,210
I just want to show you how this looks like.

84
00:04:27,210 --> 00:04:30,390
And it is actually a syntax that will quickly

85
00:04:30,390 --> 00:04:33,610
become familiar the more you work with it.

86
00:04:33,610 --> 00:04:36,290
Again, the official docs or dedicated courses

87
00:04:36,290 --> 00:04:38,930
are great places to dive deeper into that.

88
00:04:38,930 --> 00:04:39,763
But of course,

89
00:04:39,763 --> 00:04:42,450
we're also going to work with Mongo DB

90
00:04:42,450 --> 00:04:44,600
and also run different kinds of queries,

91
00:04:44,600 --> 00:04:46,640
again throughout this course, for example,

92
00:04:46,640 --> 00:04:48,313
in the next course section.

93
00:04:49,390 --> 00:04:52,700
So that's how we can query data and how we can insert data.

94
00:04:52,700 --> 00:04:54,650
Now let's also quickly, again,

95
00:04:54,650 --> 00:04:57,143
practice updating and deleting data.

96
00:04:58,120 --> 00:04:58,953
And for this,

97
00:04:58,953 --> 00:05:02,560
I'll come back to my restaurants and find all my restaurants

98
00:05:02,560 --> 00:05:03,440
here.

99
00:05:03,440 --> 00:05:04,760
And let's see here.

100
00:05:04,760 --> 00:05:08,380
I actually do want to update the address

101
00:05:08,380 --> 00:05:10,263
of my Munich Schnitzelhouse again.

102
00:05:11,140 --> 00:05:11,973
Now of course,

103
00:05:11,973 --> 00:05:14,400
also feel free to practice this on your own.

104
00:05:14,400 --> 00:05:17,860
We did already make such update a couple of lectures

105
00:05:17,860 --> 00:05:18,833
ago already.

106
00:05:19,990 --> 00:05:22,520
Now I will grab this ID here.

107
00:05:22,520 --> 00:05:23,712
Actually,

108
00:05:23,712 --> 00:05:27,110
we can grab this entire code snippet here to identify

109
00:05:27,110 --> 00:05:31,090
this restaurant by this ID and then to update it,

110
00:05:31,090 --> 00:05:34,520
we can run update one because I only want to update

111
00:05:34,520 --> 00:05:38,120
the first matching document and look for the document

112
00:05:38,120 --> 00:05:41,760
where the ID is equal to this object ID.

113
00:05:41,760 --> 00:05:44,730
And then we pass a second argument,

114
00:05:44,730 --> 00:05:47,850
a second parameter value to update one.

115
00:05:47,850 --> 00:05:51,220
And here you now use the special dollar sign set key,

116
00:05:51,220 --> 00:05:52,843
which is understood by Mongo DB.

117
00:05:53,870 --> 00:05:56,350
And another pair of curly braces.

118
00:05:56,350 --> 00:05:59,130
So you work a lot of curly braces when working with

119
00:05:59,130 --> 00:06:01,400
Mongo DB, as you can see.

120
00:06:01,400 --> 00:06:03,970
And then here we point at our nested field

121
00:06:03,970 --> 00:06:08,970
by using address dot street between quotes, like this.

122
00:06:09,330 --> 00:06:11,240
And then the value you want to set here,

123
00:06:11,240 --> 00:06:13,003
let's say schnitzel street.

124
00:06:14,150 --> 00:06:16,870
And this is how we could update the street field

125
00:06:16,870 --> 00:06:19,930
in the nested address document in the restaurant

126
00:06:19,930 --> 00:06:20,943
with this ID.

127
00:06:22,570 --> 00:06:23,670
Hit enter.

128
00:06:23,670 --> 00:06:26,510
You'll see one document was modified.

129
00:06:26,510 --> 00:06:30,803
And if we now, again, simply find all restaurants,

130
00:06:31,890 --> 00:06:33,563
here we have the new street.

131
00:06:35,710 --> 00:06:36,830
Now last, but not least,

132
00:06:36,830 --> 00:06:39,220
we can of course also delete documents.

133
00:06:39,220 --> 00:06:41,873
And for example, delete a review.

134
00:06:42,740 --> 00:06:45,370
For this, I'll quickly find all of them again.

135
00:06:45,370 --> 00:06:48,170
And let's say, I want to delete to this first review.

136
00:06:48,170 --> 00:06:51,740
Well, then we can just grab that ID to identify it

137
00:06:51,740 --> 00:06:52,823
by that ID.

138
00:06:54,780 --> 00:06:58,840
And then run db reviews delete one.

139
00:06:58,840 --> 00:07:02,070
And between curly braces search for the ID,

140
00:07:02,070 --> 00:07:05,780
which has this object ID and hit enter.

141
00:07:05,780 --> 00:07:08,770
And now this was deleted. And of course, therefore,

142
00:07:08,770 --> 00:07:11,200
if we try to find all the reviews,

143
00:07:11,200 --> 00:07:12,913
this review is now missing.

144
00:07:14,580 --> 00:07:18,320
So these are the CRUD operations we can run with Mongo DB.

145
00:07:18,320 --> 00:07:22,550
That's the general base syntax you should understand.

146
00:07:22,550 --> 00:07:25,730
Again, we'll see more examples throughout this course.

147
00:07:25,730 --> 00:07:27,070
And most importantly,

148
00:07:27,070 --> 00:07:30,270
you now should understand what the idea is behind

149
00:07:30,270 --> 00:07:33,480
storing data in a NoSQL database.

150
00:07:33,480 --> 00:07:36,110
That we don't work with dozens of tables,

151
00:07:36,110 --> 00:07:39,300
but that we instead try to plan for the queries

152
00:07:39,300 --> 00:07:42,760
we're about to run and that we then store relate data

153
00:07:42,760 --> 00:07:43,630
together.

154
00:07:43,630 --> 00:07:45,070
Not all the time.

155
00:07:45,070 --> 00:07:47,760
As you saw with restaurants and reviews,

156
00:07:47,760 --> 00:07:51,950
where we still had two collections, but often as you,

157
00:07:51,950 --> 00:07:52,783
for example,

158
00:07:52,783 --> 00:07:55,410
saw with restaurants and the addresses

159
00:07:55,410 --> 00:07:56,913
of these restaurants.

