1
00:00:02,700 --> 00:00:04,830
Now we did insert some data.

2
00:00:04,830 --> 00:00:07,939
So that's the C of the Crowd Operations.

3
00:00:07,939 --> 00:00:10,110
Now, how can we get that data?

4
00:00:10,110 --> 00:00:13,040
How can we read that data?

5
00:00:13,040 --> 00:00:17,653
Well, that is thankfully also rather straight forward.

6
00:00:18,500 --> 00:00:19,960
To read our data.

7
00:00:19,960 --> 00:00:24,950
So to do something on the R of the Crowd Operations.

8
00:00:24,950 --> 00:00:28,170
We can simply, again, type DB.

9
00:00:28,170 --> 00:00:29,820
Then the name of our collection,

10
00:00:29,820 --> 00:00:32,780
which was created automatically, as I told you,

11
00:00:32,780 --> 00:00:35,390
as soon as we started inserting data.

12
00:00:35,390 --> 00:00:38,380
And then to get all the documents in this collection,

13
00:00:38,380 --> 00:00:41,193
you can just execute, find like this.

14
00:00:42,290 --> 00:00:45,900
And this will then find you all the data in there.

15
00:00:45,900 --> 00:00:46,910
And as you can see,

16
00:00:46,910 --> 00:00:49,330
here we've got the two documents we inserted

17
00:00:49,330 --> 00:00:54,123
with that automatically generated ID and the data we added.

18
00:00:55,860 --> 00:00:57,230
Now, of course, you don't always wanna

19
00:00:57,230 --> 00:01:01,340
find all the documents and therefore you can also filter.

20
00:01:01,340 --> 00:01:04,370
You filter by passing a JavaScript object.

21
00:01:04,370 --> 00:01:06,430
So to say, to find

22
00:01:06,430 --> 00:01:09,140
which now does not define a document

23
00:01:09,140 --> 00:01:11,550
you wanna insert of course, but instead,

24
00:01:11,550 --> 00:01:15,040
which simply is used to group the different options

25
00:01:15,040 --> 00:01:18,260
or conditions for finding.

26
00:01:18,260 --> 00:01:20,550
And here you can simply reference

27
00:01:20,550 --> 00:01:23,490
the different keys you have in your documents.

28
00:01:23,490 --> 00:01:27,670
For example, you could point at name year.

29
00:01:27,670 --> 00:01:29,050
And then after a colon,

30
00:01:29,050 --> 00:01:32,530
you specify the value you wanna look for.

31
00:01:32,530 --> 00:01:36,730
For example, if I look for a Munich Schnitzelhouse here

32
00:01:36,730 --> 00:01:40,280
and I now hit enter, I only find one document, of course,

33
00:01:40,280 --> 00:01:43,113
because I only have one document with this name.

34
00:01:44,080 --> 00:01:47,350
And of course you can also not just look for equality,

35
00:01:47,350 --> 00:01:50,010
but in stat, if you're working with numbers,

36
00:01:50,010 --> 00:01:51,480
you can also look for a greater

37
00:01:51,480 --> 00:01:54,530
or smaller than numbers and so on.

38
00:01:54,530 --> 00:01:56,543
So there's a lot you can do here.

39
00:01:58,000 --> 00:02:01,740
Now, when you find documents, you also don't have to include

40
00:02:01,740 --> 00:02:06,330
all the key value pairs of the documents in the results set.

41
00:02:06,330 --> 00:02:11,330
Instead, if you wanna let's say, find all your documents.

42
00:02:11,700 --> 00:02:15,520
So I switched us back to find without any argument,

43
00:02:15,520 --> 00:02:18,700
but then I'm only interested in the name of the restaurants,

44
00:02:18,700 --> 00:02:20,490
but not in the address.

45
00:02:20,490 --> 00:02:23,470
Then you can simply pass an empty object

46
00:02:23,470 --> 00:02:27,040
as a value for the conditions parameter.

47
00:02:27,040 --> 00:02:31,320
And then add a comma to pass an optional second parameter.

48
00:02:31,320 --> 00:02:34,330
Which is another object where you now control

49
00:02:34,330 --> 00:02:39,330
the so-called protection of the documents that are found.

50
00:02:39,390 --> 00:02:42,030
For example, here you can type name one.

51
00:02:42,030 --> 00:02:44,923
Which means that you want to include the Name Field.

52
00:02:46,320 --> 00:02:49,100
If you hit enter, now we get back all the documents,

53
00:02:49,100 --> 00:02:51,680
but for every document, we only see the name.

54
00:02:51,680 --> 00:02:54,540
In the collection, we still have the extra data

55
00:02:54,540 --> 00:02:57,140
like the address, but here in the result,

56
00:02:57,140 --> 00:02:58,650
we only get back the name.

57
00:02:58,650 --> 00:03:00,753
And by default all the ID.

58
00:03:01,610 --> 00:03:04,980
If you don't want the ID, you can also add underscore ID.

59
00:03:04,980 --> 00:03:06,780
Since that's the name of the ID Field

60
00:03:06,780 --> 00:03:08,903
and type zero to exclude it.

61
00:03:09,850 --> 00:03:14,010
And in general, by typing zero for a field it's excluded.

62
00:03:14,010 --> 00:03:15,950
By typing one it's included.

63
00:03:15,950 --> 00:03:18,450
And if you include at least one field,

64
00:03:18,450 --> 00:03:21,150
all other fields, except for the ID

65
00:03:21,150 --> 00:03:23,593
are automatically excluded.

66
00:03:25,070 --> 00:03:27,270
So that's how you can control which fields

67
00:03:27,270 --> 00:03:29,790
you wanna get for which documents.

68
00:03:29,790 --> 00:03:31,860
So the first parameter value

69
00:03:31,860 --> 00:03:33,540
allows you to define conditions,

70
00:03:33,540 --> 00:03:35,980
to control which documents are fetched.

71
00:03:35,980 --> 00:03:39,020
The second parameter value allows you to control

72
00:03:39,020 --> 00:03:43,020
which fields are shown for the fetched documents.

73
00:03:43,020 --> 00:03:44,970
And that's how you can query your data.

74
00:03:46,070 --> 00:03:49,220
Now, sometimes you'll also wanna

75
00:03:49,220 --> 00:03:52,190
get exactly one document and you know,

76
00:03:52,190 --> 00:03:54,940
that you wanna get only one document.

77
00:03:54,940 --> 00:03:59,050
For example, if I, again, filter for the documents

78
00:03:59,050 --> 00:04:01,500
where the name is Munich Schnitzelhouse.

79
00:04:01,500 --> 00:04:04,000
I know that there is only one document

80
00:04:04,000 --> 00:04:05,693
in there that has this name.

81
00:04:06,610 --> 00:04:08,570
It would even be clearer, if I would be looking

82
00:04:08,570 --> 00:04:13,180
for the specific ID of this document.

83
00:04:13,180 --> 00:04:17,640
Still, if you look closely, you see that the actual result

84
00:04:17,640 --> 00:04:20,120
I get back here is an array.

85
00:04:20,120 --> 00:04:21,793
It's a list of documents.

86
00:04:22,660 --> 00:04:26,750
The reason for that is, that if you're using Find MongoDB,

87
00:04:26,750 --> 00:04:30,440
doesn't know if there will only be one match.

88
00:04:30,440 --> 00:04:33,780
We know that there is only one restaurant with that name,

89
00:04:33,780 --> 00:04:35,600
but that's of course not guaranteed.

90
00:04:35,600 --> 00:04:39,070
We could have multiple restaurants with that name.

91
00:04:39,070 --> 00:04:42,870
And therefore, if you only wanna get one document,

92
00:04:42,870 --> 00:04:44,995
the first matching document in case

93
00:04:44,995 --> 00:04:47,220
you would have multiple matches.

94
00:04:47,220 --> 00:04:51,883
Then instead of using Find, you can use Find one.

95
00:04:53,060 --> 00:04:55,940
And then still pass, your filtering condition

96
00:04:55,940 --> 00:04:57,950
as a first parameter value.

97
00:04:57,950 --> 00:05:01,920
And you could still also set up projection here .

98
00:05:01,920 --> 00:05:05,220
With Find One, I also get only that one document,

99
00:05:05,220 --> 00:05:07,440
but now it's not inside of an array.

100
00:05:07,440 --> 00:05:08,400
It's not a list.

101
00:05:08,400 --> 00:05:11,010
Instead, it's the first matching document

102
00:05:11,010 --> 00:05:12,873
that met this condition.

103
00:05:14,350 --> 00:05:18,040
So find, and find one with the configurations I showed you.

104
00:05:18,040 --> 00:05:22,043
Here are your reference if you wanna find and query data.

105
00:05:22,880 --> 00:05:25,540
Now, of course there is way more you can do.

106
00:05:25,540 --> 00:05:29,090
Different ways of structuring your conditions and so on.

107
00:05:29,090 --> 00:05:32,770
And therefore, I do have a full MongoDB course,

108
00:05:32,770 --> 00:05:34,250
if you wanna dive deeper.

109
00:05:34,250 --> 00:05:38,650
Or you check out the official free MongoDB documentation.

110
00:05:38,650 --> 00:05:41,860
This course will only get you started with MongoDB.

111
00:05:41,860 --> 00:05:43,110
For a deep dive,

112
00:05:43,110 --> 00:05:46,230
definitely visit that official documentation.

113
00:05:46,230 --> 00:05:48,913
Or have a look at that full course I got.

114
00:05:49,840 --> 00:05:52,530
But now with that recovered the C and the R

115
00:05:52,530 --> 00:05:54,300
of the Crowd Operations.

116
00:05:54,300 --> 00:05:57,193
Now let's see how we can update data.

