1 00:00:00,750 --> 00:00:09,539 Well, in this video and in the next two we are going to create, on the one hand, 2 00:00:11,599 --> 00:00:18,239 the scheme and the model of the data that we want to save in our MongoDB. Remember that 3 00:00:18,239 --> 00:00:29,000 Mongo allows us to save collections, documents with different number of key value fields, 4 00:00:29,000 --> 00:00:34,759 ok and that in some way we have to validate it because if not it would be crazy then 5 00:00:36,119 --> 00:00:42,119 on the one hand we are going to do that the scheme and the model on the other hand we are going to do the different 6 00:00:42,119 --> 00:00:52,700 routes remember that the development that we are doing on the one hand we are going to see how to log or 7 00:00:52,700 --> 00:00:58,380 register a user on our server and on the other hand once that user exists how 8 00:00:58,380 --> 00:01:09,120 can save, create, eliminate different tasks, then in this video what we are going to see is how to 9 00:01:09,120 --> 00:01:18,480 make those schemes and these models, we will see some types of personalized validations, well 10 00:01:18,480 --> 00:01:28,980 personalized it gives us the mongoose itself and that's it, then here we are going to come to the 11 00:01:28,980 --> 00:01:35,159 models folder and in models we are going to create a file that obviously you can put the name that 12 00:01:35,159 --> 00:01:53,120 you want, okay, I'm going to put the user model, we're going to put it all in the lower case, a better 13 00:01:53,120 --> 00:02:02,019 user point model point j s is always j s as we are doing so far, it is worth using the 14 00:02:02,019 --> 00:02:09,919 model point j s I know because what I am going to do here is the scheme and then passing the model 15 00:02:09,919 --> 00:02:20,039 of mongoose of the data when I register a user is worth then because of there the user model 16 00:02:20,039 --> 00:02:27,060 because it is the model and js because it is javascript is worth then we are already in our file in white 17 00:02:27,060 --> 00:02:38,599 we start to work on it as I told you to make that template that scheme of the values that 18 00:02:38,599 --> 00:02:48,539 we are going to put in this document because we are going to use mongoose ok then we are going to 19 00:02:48,539 --> 00:03:01,370 as always first we import what I need to import because mongoose mongoose from mongoose 20 00:03:01,370 --> 00:03:16,250 What is the next thing I do? Well, we are going to generate the scheme, the scheme, there you are, okay, the scheme, the 21 00:03:16,250 --> 00:03:31,669 scheme of those data then this is worth if we go to the technical documentation of mongoose 22 00:03:31,669 --> 00:03:40,129 which is what I have already told you in several videos you have to get used to using that documentation 23 00:03:40,129 --> 00:03:53,530 we can see some changes as it can be, for example, well here we see the validations that 24 00:03:53,530 --> 00:04:01,590 now I will use them, it is worth if I come to populate because for example here this is something we go the same 25 00:04:01,590 --> 00:04:07,289 that we are going to create with the skin and in the end what we are going to do is convert 26 00:04:07,289 --> 00:04:14,370 to a good model then look like here instead of the import or the export what it says is the 27 00:04:14,370 --> 00:04:22,790 conch mongoose is equal to the request of mongoose this is the same as the import mongoose from mongoose 28 00:04:22,790 --> 00:04:32,649 is worth and then instead of using the mongoose point skin as I have said is that what you do is 29 00:04:32,649 --> 00:04:39,850 with between keys that function of mongoose that I want to use and where I get them from mongoose 30 00:04:39,850 --> 00:04:46,329 ok and from there everything would be more or less the same you see that there is an idea a name a good age here 31 00:04:46,329 --> 00:04:52,629 there is documentation that is information as it cannot be otherwise that it is interesting that you also 32 00:04:52,629 --> 00:05:06,329 learn to use it, then well, having said that, I go back to our application and we continue 33 00:05:06,329 --> 00:05:14,569 working then what fields am I going to ask or what camps and what fields are we going to ask our 34 00:05:14,569 --> 00:05:25,550 client that he gives us to register is worth then on the one hand it can be typical the user name 35 00:05:26,509 --> 00:05:35,699 on the other hand because the password we are going to put the first gmail 36 00:05:35,699 --> 00:05:51,579 e-mail, we are going to put the password, 37 00:05:54,899 --> 00:06:01,939 well, we would put the fields that you can think of, it is worth using the user name, the e-mail and the 38 00:06:01,939 --> 00:06:09,439 pass because they are the classics and in this example that we are doing because they are the ones that are 39 00:06:09,439 --> 00:06:17,240 usually used ok then what is what I am putting now because the type of data the restrictions 40 00:06:17,240 --> 00:06:24,939 that have valid restrictions no good validations ok that we are going to give ourselves then that 41 00:06:24,939 --> 00:06:36,699 I am going to put it between keys here I now put the fields that are worth within the 42 00:06:36,699 --> 00:06:43,699 properties of the field and use name after the key I put an important comma if not it will give you 43 00:06:43,699 --> 00:06:50,459 an error here I do the same and here I do the same 44 00:06:53,279 --> 00:07:07,480 and it is good that it is the first the first property that I have to say among us of these fields because the 45 00:07:07,480 --> 00:07:14,500 the field type, then the user name, the email and the password will be of the string type but 46 00:07:14,500 --> 00:07:21,600 you should know that types of data can also be used because the name of the date is going to be a 47 00:07:21,600 --> 00:07:33,459 boolean an array is worth there are several types of data that you can have them all 48 00:07:33,459 --> 00:07:43,420 in the documentation of mongoose, okay, in principle, we are going to use 49 00:07:43,420 --> 00:07:57,769 the stream type ones, okay, so I'm going to pass the type string, okay, I'm going to pass the 50 00:07:57,769 --> 00:08:15,579 type the type string and we are going to pass here also the type this is worth then this 51 00:08:15,579 --> 00:08:26,779 say the type you have to say yes or yes ok for example validations because we are going to put 52 00:08:26,779 --> 00:08:34,840 here a comma and I am going to put it because the typical validation of the required or not is 53 00:08:34,840 --> 00:08:41,299 required that field is valid then because that for example in the user in the email and in the password 54 00:08:41,299 --> 00:08:48,460 the normal thing is that those fields are required, it is mandatory that the user gives us that 55 00:08:48,460 --> 00:08:59,950 information then it is required two points we tell the other and also 56 00:09:09,740 --> 00:09:10,440 and also 57 00:09:10,440 --> 00:09:28,360 ok what other validation can we put for example there is another one that is the trim tr and m that 58 00:09:28,360 --> 00:09:33,759 what it does is remove the blank spaces that are before and after the string chain that 59 00:09:33,759 --> 00:09:40,120 the user is going to pass to us ok then that is comfortable then here I am going to put 60 00:09:40,120 --> 00:09:58,080 32 points equal to you and we are going to put the comma here that I had forgotten and here we are going to say 61 00:10:02,370 --> 00:10:02,970 3 62 00:10:02,970 --> 00:10:17,659 here I am missing the comma also in the password because I am not going to say anything about the spaces that 63 00:10:17,659 --> 00:10:25,419 I removed them before or after, then we can put for example because the email in our 64 00:10:25,419 --> 00:10:30,580 database is unique, it is worth then we use the validation and unique 65 00:10:30,580 --> 00:10:55,000 vale y está como no me hace falta vale y esto sería nuestro skin vale nuestro el esquema vale 66 00:10:55,000 --> 00:11:01,539 que es como se utiliza esa función de mongoose ahora esto yo lo quiero pasar a un modelo de 67 00:11:01,539 --> 00:11:09,860 mongoose to be able to work from anywhere part of my development with this model is worth 68 00:11:09,860 --> 00:11:19,059 then what am I going to do first as we have been doing so far I am going to declare 69 00:11:19,059 --> 00:11:31,659 a variable with which I am going to call for example out and use or out instead of using I am going to call 70 00:11:31,659 --> 00:11:45,899 the skin I am going to call it like this to another scheme this is wrong written ok ok and now what I am going to 71 00:11:45,899 --> 00:11:51,700 do is this this scheme I have to export it and to export it you have to convert it first 72 00:11:51,700 --> 00:12:01,399 mungus tells you to convert it first to a model and that is done to export it you already know that 73 00:12:01,399 --> 00:12:11,279 is the sport of paul we are going to call this good before we put the name that we wanted to export 74 00:12:11,279 --> 00:12:17,720 here what I want is to export a model of mongoose then here I have to put mongoose point model 75 00:12:17,720 --> 00:12:25,879 ok and in the parameters that you have to pass here is first the name the name the string is worth 76 00:12:25,879 --> 00:12:32,500 as the name is being said that I want to give it then, for example, here I am going to give it 77 00:12:32,500 --> 00:12:42,200 and that is with the name that I am going to make reference from anywhere part of my development is worth 78 00:12:42,200 --> 00:12:48,500 of my back-end to work on these schemes is valid then also to the different 79 00:12:48,500 --> 00:12:55,360 values ​​that the users have passed us is worth then we have the user and on the other hand we have 80 00:12:55,360 --> 00:13:10,149 the out is that out is worth only what it does is good because it links it says the user model is based 81 00:13:10,149 --> 00:13:19,129 on the out scheme scheme is worth and in this way I can already use that scheme in any part of 82 00:13:19,129 --> 00:13:26,870 my development, it would be worth doing the same, I would have to do another js for later tasks and we will do it 83 00:13:26,870 --> 00:13:50,549 For now, this is how Mongoose works, the part of creating a data scheme and then making the Mongoose model to be able to work on that scheme.