1 00:00:00,880 --> 00:00:03,570 We've got our entire authentication system now put together. 2 00:00:03,580 --> 00:00:08,550 So now we get to start to focus on recording different location points provided by a user. 3 00:00:08,740 --> 00:00:13,910 Let's first understand the exact nature of the data that we're gonna store inside of our Mongo database. 4 00:00:14,840 --> 00:00:15,340 OK. 5 00:00:15,360 --> 00:00:16,560 Quick diagram. 6 00:00:16,560 --> 00:00:21,360 So remember we're going to record a series of points as a user walks around the world. 7 00:00:21,510 --> 00:00:27,180 So we're going to store the series of points inside of a record called a track a track essentially meaning 8 00:00:27,390 --> 00:00:32,970 here's a track or kind of a path that a user walked around the world inside of every track that we store 9 00:00:32,970 --> 00:00:34,170 inside of our database. 10 00:00:34,200 --> 00:00:40,240 We're going to have the user I.D. That is the idea the person who created this track every track is 11 00:00:40,240 --> 00:00:42,430 also going to have a name provided by a user. 12 00:00:42,580 --> 00:00:47,860 And it's going to have a array of different point objects that we're going to store under a location's 13 00:00:47,860 --> 00:00:48,880 property. 14 00:00:48,910 --> 00:00:53,680 So this array of point objects is going to be the actual kind of mapped path that the user makes through 15 00:00:53,680 --> 00:00:58,480 the world every point inside that array is going to have a timestamp. 16 00:00:58,630 --> 00:01:02,890 So that's the actual time that the user was at each point in the world. 17 00:01:02,890 --> 00:01:08,430 It's also going to have a coords object chords being short for coordinates inside this object. 18 00:01:08,440 --> 00:01:13,390 We're going to have latitude longitude altitude accuracy heading and speed. 19 00:01:13,440 --> 00:01:18,150 Now this object structure right here of having like a timestamp and then a separate object called coords 20 00:01:18,150 --> 00:01:21,410 with all those properties inside of it might seem a bit strange. 21 00:01:21,420 --> 00:01:26,370 The reason we're doing it this way is that this right here is essentially the exact object that we get 22 00:01:26,370 --> 00:01:31,680 from a mobile device with React Native that describes a user's current location through essentially 23 00:01:31,680 --> 00:01:36,570 just taking the information directly off the phone and throwing it into our database in the exact same 24 00:01:36,570 --> 00:01:39,420 format without making any changes to it. 25 00:01:39,420 --> 00:01:43,950 So again we're going to create a track every track is gonna have a user I.D. and a name and then an 26 00:01:43,950 --> 00:01:49,680 array of those point objects so to start implementing this inside of our server we're going to first 27 00:01:49,680 --> 00:01:54,240 flip on over to our code editor and we're gonna find that model's directory once again. 28 00:01:54,330 --> 00:02:00,340 So we're going to create a new model so we can represent this collection of tracks inside of our database. 29 00:02:00,420 --> 00:02:06,810 So inside of models I'll make a new file called Track dot J.S. than inside of here we're gonna write 30 00:02:06,810 --> 00:02:10,070 out some code that looks very similar to what we put inside of user J.S.. 31 00:02:10,110 --> 00:02:12,390 So at the very top we're going to require in Mongoose 32 00:02:16,270 --> 00:02:19,270 we're then going to use that to create a track schema 33 00:02:24,300 --> 00:02:28,770 then inside of here we're going to list out all the different properties that we expect a track to have. 34 00:02:28,770 --> 00:02:35,160 So as we just discussed first off it's going to have a user I.D. a user I.D. is going to be a type Mongoose 35 00:02:35,310 --> 00:02:44,210 dot schema with a capital S types object I.D. and notice how object idea has capital ie lowercase d. 36 00:02:44,430 --> 00:02:51,020 This is how we indicate that user I.D. is a reference to some other object stored inside of Mongo DV. 37 00:02:51,120 --> 00:02:56,970 We're also going to give it a ref property of user the ref property is used specifically by Mongoose 38 00:02:57,150 --> 00:03:02,940 and he essentially tells that this user I.D. is pointing at an instance of a user as was defined inside 39 00:03:02,940 --> 00:03:10,550 of our user dot J.S. file that ref of user points it to this model string right here of capital you 40 00:03:10,580 --> 00:03:11,620 user. 41 00:03:11,620 --> 00:03:18,030 So that's how mongoose is going to understand that user I.D. is pointing at an instance of a user then 42 00:03:18,030 --> 00:03:21,080 after that will indicate that this is also going to have a name property. 43 00:03:21,120 --> 00:03:26,420 So that's gonna be a type string and we'll give it a default value of empty string like so. 44 00:03:26,860 --> 00:03:32,130 So if for some crazy reason someone creates a track without a name assigned to it we'll have a default 45 00:03:32,130 --> 00:03:34,480 name of just empty string. 46 00:03:34,710 --> 00:03:39,240 And then finally we can indicate that there's also going to be a series of locations or in array of 47 00:03:39,240 --> 00:03:39,950 locations. 48 00:03:40,140 --> 00:03:45,720 So to indicate that we'll put down locations will then put down a set of square brackets and inside 49 00:03:45,720 --> 00:03:49,020 there we're gonna refer to a separate schema object. 50 00:03:49,080 --> 00:03:53,310 So this separate schema object is going to describe the different objects that are going to be inside 51 00:03:53,310 --> 00:03:59,500 of this array we're going to define that point schema in the same way that we just defined the schema 52 00:03:59,500 --> 00:04:00,270 right here. 53 00:04:00,310 --> 00:04:04,900 We're going to do it in the same file because point schema is only going to make any sense in relation 54 00:04:04,900 --> 00:04:06,150 to our track. 55 00:04:06,400 --> 00:04:11,020 We have to define point schema right above track schema because well we reference that variable right 56 00:04:11,020 --> 00:04:16,540 there right above track schema will define a second schema called point schema 57 00:04:20,050 --> 00:04:25,000 so once again this point schema is going to represent one individual recorded point that we collected 58 00:04:25,030 --> 00:04:29,440 off a mobile device in the world and it's going to have all those different properties U.S. listed right 59 00:04:29,440 --> 00:04:30,090 there. 60 00:04:30,100 --> 00:04:33,880 So we need to define all those different properties inside of our point schema. 61 00:04:34,070 --> 00:04:36,570 So a first take care of timestamp. 62 00:04:36,580 --> 00:04:39,370 So timestamp is going to be a number. 63 00:04:39,400 --> 00:04:44,110 Now once again that might be a little bit surprising usually a timestamp is like a date object where 64 00:04:44,110 --> 00:04:50,050 a string or something like that when we pull a user's location off their mobile device we get the current 65 00:04:50,050 --> 00:04:57,130 time or the time at which that location was pulled inside of a strew a number like a simple long number 66 00:04:57,130 --> 00:05:00,680 that represents the number of milliseconds since 1970. 67 00:05:00,700 --> 00:05:05,110 So we're once again we're just going to take that data and throw it straight into Mongo DV without messing 68 00:05:05,110 --> 00:05:07,220 around with it too much. 69 00:05:07,270 --> 00:05:11,880 There are also going to say this thing has a coords property and the coords property is going to be 70 00:05:11,880 --> 00:05:17,420 an object with a bunch of different properties inside of it so it's going to have a latitude that is 71 00:05:17,420 --> 00:05:18,420 also a number. 72 00:05:18,710 --> 00:05:30,810 We're going to have a longitude that is a number an altitude an accuracy a heading and finally a speed 73 00:05:32,100 --> 00:05:32,310 now. 74 00:05:32,310 --> 00:05:38,350 As usual I have to beg you please double check your spelling on latitude longitude altitude in accuracy 75 00:05:38,880 --> 00:05:41,180 if you make any typo on those property names right there. 76 00:05:41,250 --> 00:05:45,470 They're not gonna be safe properly inside of Mongo DB Okay. 77 00:05:45,480 --> 00:05:47,550 So we've now defined our track schema. 78 00:05:47,550 --> 00:05:48,830 It's going to reference a user. 79 00:05:48,840 --> 00:05:51,600 It's going to have a name and an array of points. 80 00:05:51,800 --> 00:05:56,220 And we defined exactly what a point is inside of a separate schema object right here. 81 00:05:56,220 --> 00:06:01,080 It's not the last thing we're going to do is load up our track schema into Mongoose so down at the bottom 82 00:06:01,080 --> 00:06:09,950 the file we'll call Mongoose dot model with track and track schema. 83 00:06:10,080 --> 00:06:15,580 We're not going to load up the point schema when we call model right here and pass in a schema. 84 00:06:15,620 --> 00:06:21,800 This is the actual step that ties some collection of data inside of Mongo D.B. to Mongoose so we don't 85 00:06:21,800 --> 00:06:27,040 really want to tie point schema with Mongoose because we're not going to have a collection of points 86 00:06:27,040 --> 00:06:28,160 schemas. 87 00:06:28,160 --> 00:06:33,020 Instead all those point objects are embedded so to speak inside of track schema. 88 00:06:33,350 --> 00:06:35,990 So we only have a collection of track objects. 89 00:06:36,110 --> 00:06:40,200 And that's why we are only loading up track into Mongoose OK. 90 00:06:40,210 --> 00:06:43,020 So that's all we have to do to create this representation of a track. 91 00:06:43,500 --> 00:06:48,360 So now we need to start to author another set of routes inside of another file inside of our routes 92 00:06:48,360 --> 00:06:54,060 directory that will allow our mobile device to create a new track or delete a track or view a track 93 00:06:54,060 --> 00:06:56,170 or whatever else we want to do. 94 00:06:56,210 --> 00:06:58,300 So let's start to take care of that in the next video.