1
00:00:12,580 --> 00:00:13,780
In this video.

2
00:00:13,810 --> 00:00:22,480
Let's get started with MongoDB by learning what is called CRUD operations, because these actions are

3
00:00:22,480 --> 00:00:25,270
needed by any application.

4
00:00:25,270 --> 00:00:31,750
So what is called operation, let's see more C stands for create.

5
00:00:31,750 --> 00:00:39,520
If you want to save something into MongoDB, we are going to use what is called create operation and

6
00:00:39,520 --> 00:00:41,440
our stand for raid.

7
00:00:41,440 --> 00:00:49,990
If you want to fetch what we have created, we are going to use the raid method and after that you stand

8
00:00:49,990 --> 00:00:51,460
for update.

9
00:00:51,460 --> 00:00:58,450
So after creating and we want to update the record, we are going to use update operation.

10
00:00:58,660 --> 00:01:02,920
And finally we have D which stands for Delete.

11
00:01:02,950 --> 00:01:07,120
If you want to delete a record, how are we going to do it?

12
00:01:07,120 --> 00:01:10,000
So let's start with create.

13
00:01:10,030 --> 00:01:15,460
How can we create, record and save into MongoDB?

14
00:01:15,490 --> 00:01:17,110
This is the time.

15
00:01:17,110 --> 00:01:18,520
Let's get rocking.

16
00:01:18,940 --> 00:01:22,390
All right, so let's see how we are going to do.

17
00:01:22,390 --> 00:01:29,230
We need to learn the MongoDB command or syntax, so let's see how we can create.

18
00:01:29,230 --> 00:01:37,570
So click on resources and click on applications and we are going to use the driver.

19
00:01:37,600 --> 00:01:43,060
So click on drivers and let's click on the Node.js.

20
00:01:43,060 --> 00:01:46,960
And now this is a guide for Node.js.

21
00:01:46,960 --> 00:01:51,760
So on the left side here, click on fundamentals.

22
00:01:51,760 --> 00:01:57,100
And here you can see that we have what is called crowd operations.

23
00:01:57,100 --> 00:02:03,100
So click on that and what we want is what you call right operations.

24
00:02:03,100 --> 00:02:05,230
So let's click on that.

25
00:02:05,230 --> 00:02:13,090
And these are the method where we can walk right record into MongoDB and you can see that we have what

26
00:02:13,090 --> 00:02:16,500
is called raid operations and you have right operation.

27
00:02:16,510 --> 00:02:23,320
Right operation simply means we can insect's modify delete the command in your MongoDB database.

28
00:02:23,320 --> 00:02:26,560
So let's click on the insect document.

29
00:02:26,560 --> 00:02:36,280
So for insect we can add record into MongoDB and we have couple of ways of inserting document or creating

30
00:02:36,280 --> 00:02:38,890
document into MongoDB.

31
00:02:38,980 --> 00:02:47,830
We have single document for this method we use to create a single record and save it into MongoDB.

32
00:02:48,100 --> 00:02:52,000
And for this we can also insect multiple document.

33
00:02:52,000 --> 00:02:57,790
So let's look at a sample of the methods and are in a single document.

34
00:02:57,790 --> 00:03:05,230
And one of them is what we call insect one and insect one resort and insect one.

35
00:03:05,230 --> 00:03:11,590
So let's get back to visual, see the code and see how we are going to write these commands to get it

36
00:03:11,590 --> 00:03:12,100
done.

37
00:03:12,100 --> 00:03:19,240
So back to visual the code before we can save record in database, we need two things.

38
00:03:19,240 --> 00:03:26,110
One is the database name that we want to write into, and secondly, the collection.

39
00:03:26,110 --> 00:03:31,600
So let's go ahead and create the database and our collection.

40
00:03:31,690 --> 00:03:39,640
Remember, we can also do the same thing from our dashboard, but let's create the database for our

41
00:03:39,640 --> 00:03:40,150
code.

42
00:03:40,150 --> 00:03:42,190
So here we go.

43
00:03:42,190 --> 00:03:48,190
So after connecting, then down here we can go ahead and create new database.

44
00:03:48,190 --> 00:03:54,640
So here is a syntax, create new DB or database for short.

45
00:03:54,640 --> 00:03:55,810
So here we go.

46
00:03:55,840 --> 00:03:59,500
Cost database or db.

47
00:03:59,530 --> 00:04:01,060
Let's make it db for short.

48
00:04:01,060 --> 00:04:09,730
DB is equal to client which is from this one after initialization of the mongo client.

49
00:04:10,000 --> 00:04:18,010
On that, we have a method for MongoDB called DB meaning database and here we pass in the database name.

50
00:04:18,040 --> 00:04:21,339
Let's say we are creating database for as school.

51
00:04:21,339 --> 00:04:23,920
So this is my database.

52
00:04:24,220 --> 00:04:29,320
So after creating it, the next step is I need to create a collection.

53
00:04:29,320 --> 00:04:36,370
Remember a database comprises of collection because for our school we can have courses, we can have

54
00:04:36,370 --> 00:04:40,930
users, we can have employees and many more or departments.

55
00:04:40,930 --> 00:04:45,460
So we need to create collections where we can keep it inside our database.

56
00:04:45,460 --> 00:04:47,950
So next step is create collection.

57
00:04:51,290 --> 00:04:54,800
So here you go comes the name of the collection.

58
00:04:54,800 --> 00:04:56,300
Let's call this one.

59
00:04:56,630 --> 00:04:57,410
Students.

60
00:04:58,070 --> 00:05:04,460
Students collection which is equal to DB dot collection.

61
00:05:04,460 --> 00:05:08,190
And how pass in the collection name for this one.

62
00:05:08,210 --> 00:05:10,010
I would say students.

63
00:05:10,160 --> 00:05:13,760
Students collection and that is it.

64
00:05:13,790 --> 00:05:22,100
So if I try to console.log student collection, I believe we are going to see empty collection.

65
00:05:22,100 --> 00:05:31,070
So let's get back to Terminus here and then restart my application and let's see where I get an object

66
00:05:31,070 --> 00:05:31,970
with properties.

67
00:05:31,970 --> 00:05:40,220
So but if you get back to the MongoDB dashboard here now when I click on Browse collection, let's see

68
00:05:40,220 --> 00:05:42,350
the collection that we have.

69
00:05:42,500 --> 00:05:49,850
Well, we still see empty collection simply because there is no record inside the collection.

70
00:05:49,850 --> 00:05:55,490
So as soon as we insert a record into collection, we are going to see some data here.

71
00:05:55,490 --> 00:05:57,170
So let's continue.

72
00:05:57,260 --> 00:06:01,460
So now we are done with the creating of the database and then the collection.

73
00:06:01,460 --> 00:06:04,600
The next step is let's create document.

74
00:06:04,610 --> 00:06:11,510
So here we go, create document and that is the student.

75
00:06:11,870 --> 00:06:14,300
So let's create a sample student here.

76
00:06:14,330 --> 00:06:16,040
So here we go.

77
00:06:16,040 --> 00:06:18,500
How can we create students?

78
00:06:18,830 --> 00:06:22,160
Remember, we got the students document here.

79
00:06:22,160 --> 00:06:29,840
So on this one we can use all the operations like delete update on this collection called Students.

80
00:06:29,840 --> 00:06:31,580
So here we go.

81
00:06:32,150 --> 00:06:36,590
So our code, this one const student.

82
00:06:37,480 --> 00:06:38,200
One.

83
00:06:38,650 --> 00:06:42,210
Equal to the student collection, which is this one.

84
00:06:42,220 --> 00:06:51,370
On that we have a method called insect insect one meaning I want to create a single user or student.

85
00:06:51,370 --> 00:06:55,420
So here are parts in an object with properties.

86
00:06:55,420 --> 00:06:59,640
So here I provide the name of the student.

87
00:06:59,650 --> 00:07:01,660
I would say John Doe.

88
00:07:02,910 --> 00:07:06,670
And next is, let's say, the email of the student.

89
00:07:06,690 --> 00:07:12,060
Let me provide a city of the students and let's say Kumasi as that.

90
00:07:12,300 --> 00:07:17,340
Now, do you remember I made mentioned that MongoDB is seamless?

91
00:07:17,370 --> 00:07:18,990
Here is the answer.

92
00:07:19,320 --> 00:07:26,790
If we see that we are not specifying what we want to create, but instead we can insert any record into

93
00:07:26,790 --> 00:07:27,720
MongoDB.

94
00:07:27,810 --> 00:07:34,340
But if you are working with relational database, unless you specify the things that you want to create,

95
00:07:34,350 --> 00:07:36,330
how awesome is MongoDB?

96
00:07:36,660 --> 00:07:41,040
So with this one is going to take some time to create.

97
00:07:41,040 --> 00:07:46,240
It can be successful or not, so we need to handle the promise.

98
00:07:46,260 --> 00:07:53,430
And lucky for us, because our function, we have marked this one as an async, I can go ahead and await

99
00:07:53,430 --> 00:07:59,970
the action as that with it here and now if I go ahead and console.log.

100
00:07:59,970 --> 00:08:01,980
Student one Save it.

101
00:08:01,980 --> 00:08:03,990
And now, moment of truth.

102
00:08:04,500 --> 00:08:13,620
Let's clear the console and restart the file and let's see if we are going to see student a acknowledged

103
00:08:13,650 --> 00:08:17,310
meaning that we are able to create a student.

104
00:08:17,340 --> 00:08:24,330
We see a property called acknowledged meaning true, which means that it is successful and to know that

105
00:08:24,330 --> 00:08:25,320
it is successful.

106
00:08:25,320 --> 00:08:34,169
MongoDB has given us infected ID and MongoDB has represented that particular student with this ID.

107
00:08:34,200 --> 00:08:36,450
How awesome it is.

108
00:08:36,570 --> 00:08:39,570
So back to MongoDB dashboard.

109
00:08:39,720 --> 00:08:44,280
If I refresh it, I'm going to see that red card.

110
00:08:45,120 --> 00:08:49,410
And here we go, guys.

111
00:08:49,410 --> 00:08:51,000
Are you happy about it?

112
00:08:51,460 --> 00:08:59,250
You can see that we have a school database and and that we have a collection called Student.

113
00:08:59,250 --> 00:09:07,080
And inside we have one document which is user corps John Doe from Kumasi.

114
00:09:07,380 --> 00:09:09,630
That is awesome, guys.

115
00:09:09,630 --> 00:09:11,220
That is awesome.

116
00:09:11,370 --> 00:09:13,630
Again, we can inspect more.

117
00:09:14,000 --> 00:09:15,690
Student So here we go.

118
00:09:15,840 --> 00:09:18,300
Our call this one are single.

119
00:09:21,230 --> 00:09:29,090
Ain't our copy this one and down here is that let me comment this one because I'm done with it.

120
00:09:29,090 --> 00:09:30,590
And now let me call this one.

121
00:09:30,800 --> 00:09:32,540
Student two Let me say.

122
00:09:32,540 --> 00:09:39,440
STUDENTS two Because we are going to create many students here and I'll console.log the students two

123
00:09:39,470 --> 00:09:39,980
here.

124
00:09:40,190 --> 00:09:47,630
So to be able to insert more repos to the end here, I will change the comment here to more repo record.

125
00:09:47,810 --> 00:09:50,330
So the syntax is going to be different.

126
00:09:50,330 --> 00:09:53,420
So let's see how we can insert menu record.

127
00:09:53,420 --> 00:10:02,450
And we are going to use a method called insect money and the more repo document, which is this one,

128
00:10:02,450 --> 00:10:07,910
we are going to use a method called insect money, which is this.

129
00:10:08,240 --> 00:10:09,380
So let's see.

130
00:10:09,380 --> 00:10:14,540
So instead of taking an object, insect money ticks in an array.

131
00:10:14,540 --> 00:10:24,320
So as this one and let me change the name here to insect money here, we're going to be array of students.

132
00:10:24,320 --> 00:10:27,650
So the first one going to be object with the first student's name.

133
00:10:27,680 --> 00:10:30,440
Let me call this one as.

134
00:10:31,220 --> 00:10:34,160
Emanuel and the city.

135
00:10:34,970 --> 00:10:39,410
And let me add a new student so I would copy this object.

136
00:10:39,410 --> 00:10:41,060
And here, let me pace it.

137
00:10:41,060 --> 00:10:43,070
Let me change this one to Thomas.

138
00:10:44,830 --> 00:10:48,220
And from us is also from Western.

139
00:10:49,700 --> 00:10:50,800
Okay, great.

140
00:10:50,810 --> 00:10:51,830
So let me save it.

141
00:10:51,830 --> 00:10:53,570
And now I'm console again.

142
00:10:53,570 --> 00:10:56,120
Student two So back to my terminal.

143
00:10:56,150 --> 00:10:58,220
Let me start the file and let's see.

144
00:10:59,210 --> 00:11:06,290
A quasi that I see acknowledge in sector to document and I get acknowledged true with different IDs.

145
00:11:06,290 --> 00:11:12,590
So now back to my dashboard if I refresh it and there we go.

146
00:11:12,620 --> 00:11:15,770
Let's see, we have 2 to 3 record.

147
00:11:15,770 --> 00:11:21,980
At first I added one record and next one I added to student to go.

148
00:11:22,340 --> 00:11:28,460
So in the next video, let's see how we can fetch this document and then display it inside our application.

149
00:11:28,460 --> 00:11:30,080
That is our terminal here.

