1
00:00:06,450 --> 00:00:07,710
In this video.

2
00:00:07,740 --> 00:00:16,980
Let's see how we can perform all the CRUD operations that is create, read, update and delete using

3
00:00:16,980 --> 00:00:18,030
Mongoose.

4
00:00:18,210 --> 00:00:22,940
Well, before we can do that, we need to perform two things.

5
00:00:22,950 --> 00:00:26,340
First step is we have connected to MongoDB.

6
00:00:26,880 --> 00:00:33,720
The next step is we need to create what is called schema and then after that we need to create what

7
00:00:33,720 --> 00:00:35,130
is called modal.

8
00:00:35,130 --> 00:00:40,650
These are the two things that you are going to work with any time you want to use Mongoose.

9
00:00:40,890 --> 00:00:42,540
So what is schema?

10
00:00:42,570 --> 00:00:44,730
So let's have a target here.

11
00:00:44,760 --> 00:00:53,310
What we want to do here is that we want to create a database for school and then for school we are going

12
00:00:53,310 --> 00:00:56,070
to create student or courses.

13
00:00:56,070 --> 00:01:00,000
So in that way we need to create a blueprint.

14
00:01:00,030 --> 00:01:08,700
How we can create instances, for example, instances of courses or students and save it into database.

15
00:01:08,940 --> 00:01:17,130
So back to the documentation, you can see that after it has been connected, then we create a schema

16
00:01:17,130 --> 00:01:23,400
to get what is called model and here we can use MongoDB method to get it done.

17
00:01:23,400 --> 00:01:29,010
So let's click on read documentation here and let's see the steps.

18
00:01:29,100 --> 00:01:32,550
Step number one is we need to create what is called schema.

19
00:01:32,550 --> 00:01:39,210
So let's click on defining schema, which is down here, which is this defining schema.

20
00:01:39,300 --> 00:01:49,200
So everything in Mongoose start with a schema and a schema maps to a MongoDB collection and defines

21
00:01:49,200 --> 00:01:53,130
the shape of the document within that collection.

22
00:01:53,400 --> 00:02:01,260
So the next step is the extruded schema for Mongoose and the define the blueprint down here.

23
00:02:01,290 --> 00:02:05,070
So let's do the same thing inside Visual Studio code.

24
00:02:05,460 --> 00:02:08,490
So how can we create schema for students?

25
00:02:08,490 --> 00:02:10,229
So here we go.

26
00:02:10,259 --> 00:02:19,470
We make use of student, then we add what is called schema to it and it's equal to new.

27
00:02:19,500 --> 00:02:30,630
Then we bring in Mongoose Dart schema as a function, and for this function we are going to pass in

28
00:02:30,630 --> 00:02:31,640
configuration.

29
00:02:31,650 --> 00:02:35,670
We're going to be the blueprints of how we can create students.

30
00:02:35,940 --> 00:02:43,620
So in here we pass in object, and inside here we need to specify the fields of the students.

31
00:02:43,800 --> 00:02:51,120
So in what case, let's say that for student, we need the name of the student, the city of the students,

32
00:02:51,120 --> 00:02:58,290
and let's say the course of the student, we need these three fields and this is what we want.

33
00:02:58,290 --> 00:03:00,570
So how can we specify it here?

34
00:03:00,780 --> 00:03:05,010
So inside the schema we need to provide the fields.

35
00:03:05,010 --> 00:03:08,670
The first one is name and name.

36
00:03:08,850 --> 00:03:17,130
You provide the kind of data types and in Mongoose we have couple of data types.

37
00:03:17,130 --> 00:03:24,570
So for the meantime, let me show you the first one is String and for Mongoose, all the data type start

38
00:03:24,570 --> 00:03:26,220
with the uppercase.

39
00:03:26,400 --> 00:03:29,940
For JavaScript, we start with word lua cases.

40
00:03:29,940 --> 00:03:38,160
So for mongoose, always uppercase if it's a number is going to be a number Boolean, Uppercase, Boolean

41
00:03:38,160 --> 00:03:39,450
and many more.

42
00:03:39,450 --> 00:03:46,170
And we know there are types so mongoose even extend the ties of the type that we can use.

43
00:03:46,440 --> 00:03:50,730
So if you go to the official documentation, then you click on schema type.

44
00:03:50,850 --> 00:03:59,010
Here, you're going to see all these schema types that we can use and here are examples of them we can

45
00:03:59,010 --> 00:03:59,190
use.

46
00:03:59,190 --> 00:04:05,730
String Number Data Buffer Boolean MCs, object ID Array, Decimal Map Schema.

47
00:04:06,030 --> 00:04:14,040
These are the common ones that we use string number dates, boolean arrays and sometimes we use map.

48
00:04:14,040 --> 00:04:14,490
Yeah.

49
00:04:14,490 --> 00:04:19,529
So these are the common ones that we are going to use a lot and I believe we are familiar with the other

50
00:04:19,529 --> 00:04:22,019
type when it comes to JavaScript.

51
00:04:22,019 --> 00:04:25,680
So the same thing being applied inside Mongoose.

52
00:04:25,680 --> 00:04:27,420
So here we go.

53
00:04:27,630 --> 00:04:32,010
So the first one we want to accept string of a name.

54
00:04:32,040 --> 00:04:38,910
And what about the city two, we also want to accept a string also.

55
00:04:38,910 --> 00:04:39,270
All right.

56
00:04:39,270 --> 00:04:44,010
The next one going to be the courses is going to be a ray.

57
00:04:44,010 --> 00:04:47,760
So you provide what is called array as that.

58
00:04:47,760 --> 00:04:54,180
So let's say courses and let's say that is a person married, let's say is married, let's add more

59
00:04:54,180 --> 00:04:58,200
fuel to it and we are going to use what is called boolean.

60
00:04:58,470 --> 00:05:03,780
And we can also provide the age of the students, which is a number.

61
00:05:03,810 --> 00:05:05,790
So you can see this is what.

62
00:05:06,300 --> 00:05:07,200
Destruction.

63
00:05:07,230 --> 00:05:15,780
So for this one, we have well-structured what document that we want to create as compared to normal

64
00:05:15,810 --> 00:05:16,830
MongoDB.

65
00:05:16,860 --> 00:05:18,530
There is no structure.

66
00:05:18,540 --> 00:05:22,890
We can just add anything we want and it will be saved into it.

67
00:05:23,070 --> 00:05:29,040
So with this one, if you are trying to save the command of student and the user provide a field which

68
00:05:29,040 --> 00:05:34,260
is not part of this one is not going to be saved, how awesome it is.

69
00:05:34,620 --> 00:05:38,940
So after that, we need to create what is called model.

70
00:05:39,330 --> 00:05:41,820
So let's get into that in the next video.

