1 00:00:00,840 --> 00:00:05,070 In the last section we put together a first rough draft of our survey schema. 2 00:00:05,290 --> 00:00:10,270 But the very end I was looking at this recipient's property right here and I was kind of wondering if 3 00:00:10,270 --> 00:00:12,420 it was going to work out in the end for us or not. 4 00:00:12,700 --> 00:00:16,960 So in this video we're going to talk about some considerations around the schema we've put together 5 00:00:16,960 --> 00:00:21,380 so far and we're going to decide whether or not we'd really approach this the right way. 6 00:00:21,550 --> 00:00:25,930 We're going to do this by pointing out two little deficiencies in the way that we've laid out our schema 7 00:00:25,930 --> 00:00:26,550 right now. 8 00:00:26,680 --> 00:00:31,330 And once we look at both those I think you'll have a better idea of how we're going to tweak this thing 9 00:00:31,330 --> 00:00:35,020 just a little bit to make sure that it better suits our application. 10 00:00:35,030 --> 00:00:40,810 So first thing I want to talk about is a very simple consideration and that is where do we store our 11 00:00:40,810 --> 00:00:41,520 feedback. 12 00:00:41,590 --> 00:00:47,260 So remember that same tire purposes entire application when the user clicks on yes or no right here. 13 00:00:47,350 --> 00:00:53,470 We eventually at some point in time have to make sure that we update this record of this survey to say 14 00:00:53,740 --> 00:00:55,460 hey someone clicked yes they like it. 15 00:00:55,480 --> 00:01:00,120 Hey someone clicked No they don't like it and so on and so on over and over again. 16 00:01:00,520 --> 00:01:03,800 At this point our survey has absolutely no property on it. 17 00:01:03,820 --> 00:01:08,680 That would really be appropriate for saying OK we've got another yes we got another no we got another 18 00:01:08,680 --> 00:01:09,030 yes. 19 00:01:09,040 --> 00:01:16,430 And so on some thinking that maybe we should add in two additional properties to our survey model. 20 00:01:16,700 --> 00:01:18,260 Ok so very simply named. 21 00:01:18,270 --> 00:01:19,350 You're at the bottom. 22 00:01:19,350 --> 00:01:22,580 I think that we should add in a property called Yes and that's a record. 23 00:01:22,590 --> 00:01:25,230 Every single time that someone clicks Yes. 24 00:01:25,440 --> 00:01:27,030 And then another one of no. 25 00:01:27,060 --> 00:01:29,640 And that's a record every single time someone clicks. 26 00:01:29,640 --> 00:01:30,370 No. 27 00:01:30,780 --> 00:01:33,870 Both of these can be integer or number types. 28 00:01:33,870 --> 00:01:35,230 We'll start them off at zero. 29 00:01:35,370 --> 00:01:40,320 And then every single time we detect one of these clicks we can increment either yes or no. 30 00:01:40,320 --> 00:01:44,120 Very similar similarly to how we handle the credits on the user model. 31 00:01:44,190 --> 00:01:45,720 Earlier in this course. 32 00:01:45,990 --> 00:01:52,050 So this is definitely getting us to making sure that we record feedback as it is provided to us. 33 00:01:52,260 --> 00:01:57,840 But now if you look at what we have you'll realize that there might be a another little deficiency inside 34 00:01:57,840 --> 00:01:59,430 of our model. 35 00:01:59,490 --> 00:02:04,560 I want you to imagine for a second that a user opens up on these emails and then they click the Yes 36 00:02:04,560 --> 00:02:10,010 button right here 20 times in a row or 50 times or a hundred times in a row. 37 00:02:10,410 --> 00:02:16,470 Right now looking at our survey right here we don't really necessarily have anything that says hey a 38 00:02:16,470 --> 00:02:19,760 given user has already provided some amount of feedback. 39 00:02:19,770 --> 00:02:24,690 There's really nothing inside this flow that we've spoken about so far that somehow prevents someone 40 00:02:24,690 --> 00:02:29,840 from clicking on a button multiple times just again and again and again. 41 00:02:29,880 --> 00:02:36,000 So I think that we need to introduce some additional property to our survey model that somehow records 42 00:02:36,060 --> 00:02:42,780 whether or not a given survey or someone who received this e-mail right here has submitted some feedback 43 00:02:42,780 --> 00:02:44,610 to us. 44 00:02:44,610 --> 00:02:50,340 Now as we start to think about this is very important to realize that we don't have a lot of identifying 45 00:02:50,370 --> 00:02:53,740 information about the people who receive these surveys. 46 00:02:53,910 --> 00:03:00,440 So how are we going to uniquely identify each one and then detect when a given person has voted and 47 00:03:00,450 --> 00:03:05,070 less like discount any future vote that they do for a particular survey. 48 00:03:05,460 --> 00:03:11,250 Well really the only piece of information we have to identify the people who receive these surveys is 49 00:03:11,250 --> 00:03:18,000 the recipients list right here at present that recipients list is an array of strings which is really 50 00:03:18,000 --> 00:03:21,000 not appropriate for storing any more information. 51 00:03:21,060 --> 00:03:26,070 We can't like just put some arbitrary property on the string or something like that or like attach some 52 00:03:26,070 --> 00:03:30,660 little character to it that says hey this person voted no there's definitely a better way of handling 53 00:03:30,660 --> 00:03:31,510 this. 54 00:03:31,530 --> 00:03:39,650 So here's what we're going to do inside of our recipient's property right here we are going to embed 55 00:03:40,100 --> 00:03:42,930 a sub document collection. 56 00:03:43,160 --> 00:03:50,120 So that is a term that is used by Mongo and Mongoose a sub document collection inside of this list of 57 00:03:50,120 --> 00:03:51,030 recipients. 58 00:03:51,110 --> 00:03:58,040 We are going to store a bunch of little models called recipients every single recipient will have one 59 00:03:58,130 --> 00:04:03,710 of two will have two properties in total they'll have an email property that is the email that belongs 60 00:04:03,710 --> 00:04:11,540 to them and then they will have a simple boolean flag of clicked clicked will either be true or false. 61 00:04:11,600 --> 00:04:16,850 We can started off as false and then whenever a given recipient or a given person with a particular 62 00:04:16,850 --> 00:04:25,130 e-mail clicks on a link yes or no we will flip that clicked flag over to true then any point in time 63 00:04:25,130 --> 00:04:25,880 in the future. 64 00:04:25,880 --> 00:04:31,050 Whenever someone clicks on the button we'll always check to see if the person just clicked on it with 65 00:04:31,050 --> 00:04:37,660 the given e-mail has clicked on the button before and if they have discarded the vote otherwise do count 66 00:04:37,660 --> 00:04:38,510 it. 67 00:04:38,510 --> 00:04:43,630 So I think that this will be a reasonable way of approaching this. 68 00:04:43,780 --> 00:04:48,160 So the only thing we have to do is figure out how we take care of embedding a set of documents like 69 00:04:48,160 --> 00:04:48,820 this. 70 00:04:49,000 --> 00:04:53,650 Well that's going to be its own little talk about exactly how we do this type of design with mongoose. 71 00:04:53,650 --> 00:04:58,450 So how about we just pause for a minute on worrying about this recipient list right here and for right 72 00:04:58,450 --> 00:05:00,990 now let's think a little bit about implementing these. 73 00:05:01,010 --> 00:05:02,850 Yes and no counters. 74 00:05:03,170 --> 00:05:04,990 So they're going to be pretty straightforward. 75 00:05:04,990 --> 00:05:09,340 It'll be very much like how we put together the credits counter previously. 76 00:05:09,340 --> 00:05:11,650 So let's take care of both those right now. 77 00:05:11,680 --> 00:05:17,830 I'll flip back over to my survey's schema file and I'm going to add on a property of yes we want to 78 00:05:17,830 --> 00:05:21,260 pass some configuration options to this thing specifically. 79 00:05:21,280 --> 00:05:27,590 I want to give it a type of number and I want to default its value to always start off as zero. 80 00:05:28,120 --> 00:05:31,330 And then we will do the exact same thing for no as well. 81 00:05:31,570 --> 00:05:37,310 So we'll see a type of number and we'll default it at 0 2. 82 00:05:37,330 --> 00:05:37,650 Okay. 83 00:05:37,690 --> 00:05:41,710 So this is looking pretty good now that we understand exactly what. 84 00:05:41,730 --> 00:05:42,520 Yes and No. 85 00:05:42,520 --> 00:05:44,250 Properties are doing for us. 86 00:05:44,290 --> 00:05:45,160 Let's take a break. 87 00:05:45,160 --> 00:05:50,050 When we come back in the next section we'll talk a little bit about this sub document collection thing 88 00:05:50,320 --> 00:05:53,530 and how we are going to make use of it inside of our survey schema. 89 00:05:53,680 --> 00:05:55,970 So I'll talk to you in just a minute.