1
00:00:07,810 --> 00:00:09,160
In this video.

2
00:00:09,220 --> 00:00:16,120
Before we can create a record and save into MongoDB, we need to finish up our steps.

3
00:00:16,329 --> 00:00:20,320
And the one that has left is what we call model.

4
00:00:20,350 --> 00:00:22,690
So what is a model?

5
00:00:23,020 --> 00:00:30,880
A model is a class with which we construct documents, meaning that model helps us to create, document

6
00:00:30,880 --> 00:00:33,280
and save into MongoDB.

7
00:00:33,310 --> 00:00:35,230
So how can we create it?

8
00:00:35,470 --> 00:00:42,700
So let's go ahead and create our model and here we go, const and then the name of the model.

9
00:00:42,730 --> 00:00:51,520
We often use uppercase student because model is a class of which we can create instances of student

10
00:00:51,520 --> 00:00:52,850
from this model.

11
00:00:52,870 --> 00:00:59,550
So here we go is equal to mongoose, the package that we required here.

12
00:00:59,710 --> 00:01:03,700
And on that we have a method called model.

13
00:01:03,700 --> 00:01:05,379
And that is it.

14
00:01:05,379 --> 00:01:06,710
And that is it.

15
00:01:06,730 --> 00:01:13,780
Before we continue on back to my compass, I have changed the theme of my compass.

16
00:01:13,780 --> 00:01:22,330
So if you want to change it, click on compass and theme and you can select light theme or dot team.

17
00:01:22,720 --> 00:01:27,760
Sometimes I can change a light theme or dark theme depending on my mood.

18
00:01:28,750 --> 00:01:29,380
Okay.

19
00:01:29,380 --> 00:01:36,040
So and also I have trashed all the data base with the exception of the default one.

20
00:01:36,130 --> 00:01:40,840
So to be able to delete a database, click on this icon.

21
00:01:40,900 --> 00:01:47,760
And sometimes if you are deleting, we get some message that we don't have permission to take this operation.

22
00:01:47,770 --> 00:01:56,050
So to give permission to delete a database inside your MongoDB dashboard, click on database access

23
00:01:56,050 --> 00:01:58,110
and then click on edit.

24
00:01:58,120 --> 00:02:01,450
And down here you can see that we have built in rows.

25
00:02:01,450 --> 00:02:09,639
By default it will give you read and write, so click on the dropdown and this is a default, right?

26
00:02:09,639 --> 00:02:10,270
Or privilege.

27
00:02:10,270 --> 00:02:17,380
So click on at last admin and then click on update user and then you can delete database.

28
00:02:17,410 --> 00:02:20,740
So here I don't have any database inside.

29
00:02:20,740 --> 00:02:23,110
So back to my model.

30
00:02:23,140 --> 00:02:29,980
The next argument to take is going to be the name of my collection and the name.

31
00:02:29,990 --> 00:02:35,710
Our path in here is going to be available inside my MongoDB dashboard.

32
00:02:35,770 --> 00:02:43,570
So here we often use uppercase students, but for this one, as soon as we compile it, the name of

33
00:02:43,570 --> 00:02:47,970
the first segment is going to be singular and then privileges it.

34
00:02:47,980 --> 00:02:52,420
Meaning we're going to add X to each of the variable we pass in here.

35
00:02:52,750 --> 00:02:59,130
And the next segment is the schema that we have defined, which is student schema.

36
00:02:59,380 --> 00:03:04,500
So we pass in here as student schema and that is it.

37
00:03:04,510 --> 00:03:10,750
So with this one, I can interact with MongoDB using this model.

38
00:03:10,780 --> 00:03:13,780
So anywhere in my application I refer to this.

39
00:03:13,780 --> 00:03:17,470
It means I'm making use of student model or collection.

40
00:03:17,650 --> 00:03:18,640
Let me save it.

41
00:03:18,640 --> 00:03:20,560
And now back to the terminal here.

42
00:03:20,590 --> 00:03:24,640
Let me click the console and run the file again.

43
00:03:24,640 --> 00:03:28,120
And let's see that MongoDB will be connected.

44
00:03:28,540 --> 00:03:29,260
Okay, good.

45
00:03:29,260 --> 00:03:30,550
It has been connected.

46
00:03:30,550 --> 00:03:32,200
And back to my compass.

47
00:03:32,200 --> 00:03:33,460
Let me refresh it.

48
00:03:33,460 --> 00:03:35,530
And now let's see something.

49
00:03:35,530 --> 00:03:44,890
Well, I believe that we are not going to see the collection because we haven't saved any data yet.

50
00:03:44,890 --> 00:03:49,570
So it's still loading and there will be no collection here.

51
00:03:49,750 --> 00:03:51,970
So let's get back to the code.

52
00:03:51,970 --> 00:03:59,920
And then in this video, let's see how we can create first to the end and visualize it inside our dashboard

53
00:03:59,920 --> 00:04:03,010
using Mongoose in the next video.

