1 00:00:01,480 --> 00:00:06,370 All right my friends let's implement all this concurrency control stuff inside of our tickets service. 2 00:00:06,370 --> 00:00:11,440 First we're gonna first focus on building out all these virgin stuff inside of our ticket service or 3 00:00:11,440 --> 00:00:15,670 then going to make sure that all the versioning numbers and whatnot get reflected inside of all these 4 00:00:15,670 --> 00:00:20,230 different events so eventually Mitt and we'll eventually move over to our order service and make sure 5 00:00:20,230 --> 00:00:22,940 that the order service makes use of the Virgin stuff as well. 6 00:00:23,110 --> 00:00:27,100 So ticket service first we're going to take a look at a little module that we're going to use along 7 00:00:27,100 --> 00:00:29,750 with Mongoose to handle all diverting stuff for us. 8 00:00:29,800 --> 00:00:33,850 We're gonna start to write out a test or two to make sure that it all works as we expect. 9 00:00:33,850 --> 00:00:40,430 So let's let me first show you some documentation on a module that we're going to use at NPM J Ask.com. 10 00:00:40,570 --> 00:00:48,130 We're going to look up a module called Mongoose update if current so here it is right here. 11 00:00:49,490 --> 00:00:51,890 If you want to you could certainly take a look at the documentation. 12 00:00:51,890 --> 00:00:53,960 It's actually some pretty fantastic documentation. 13 00:00:53,960 --> 00:00:55,130 It explains what it does. 14 00:00:55,220 --> 00:00:56,870 Pretty easy and straightforward. 15 00:00:57,020 --> 00:01:02,000 You will notice if you read the documentation that this thing can implement Optimistic concurrency control 16 00:01:02,060 --> 00:01:05,690 either by using a version number or by using a timestamp. 17 00:01:05,900 --> 00:01:11,150 So like an actual date time when the record was last updated that we're gonna go with the strategy of 18 00:01:11,150 --> 00:01:13,770 using a version as opposed to a timestamp. 19 00:01:14,400 --> 00:01:18,970 So we're gonna be doing inside of our app if you want to you again Take a look at the documentation 20 00:01:18,970 --> 00:01:19,260 here. 21 00:01:19,270 --> 00:01:24,070 It's really easy to get started with pretty much all we have do is imported wired it up to our schema 22 00:01:24,430 --> 00:01:28,690 the schema that we want to use this versioning stuff on and then the one reason I'm kind of showing 23 00:01:28,690 --> 00:01:31,560 you the documentation here just a little piece of trivia. 24 00:01:31,750 --> 00:01:36,310 You'll notice that if we're going to use this version no thing so version 1 version 2 version 3 and 25 00:01:36,310 --> 00:01:42,550 so on the version is gonna be set on the underscore underscore the property of the Mongoose document. 26 00:01:42,970 --> 00:01:47,620 So chances are you've seen that underscore underscore a V thing before with logos even if we take a 27 00:01:47,620 --> 00:01:52,460 look at say our postman that we've been using. 28 00:01:52,510 --> 00:01:55,640 Let's see if I can log in here really quickly. 29 00:01:55,860 --> 00:02:02,990 Come on I want to show you one log me in and then post a ticket. 30 00:02:02,990 --> 00:02:03,440 There we go. 31 00:02:03,440 --> 00:02:04,460 Finally there we go. 32 00:02:04,460 --> 00:02:04,910 Finally. 33 00:02:04,910 --> 00:02:08,230 So you can see underscoring ASCII score the right there. 34 00:02:08,240 --> 00:02:12,140 That is the version number that Mongoose implements by default but right now there's nothing to actually 35 00:02:12,150 --> 00:02:14,860 incremented nothing to say make use this value. 36 00:02:14,870 --> 00:02:19,190 Make use this flag or anything like that by default Mongoose update of current. 37 00:02:19,190 --> 00:02:22,740 That's the module we're using is going to try to use that underscore underscore the property for checking 38 00:02:22,740 --> 00:02:27,700 the version now for you and I underscoring the scurvy doesn't really have a lot of meaning. 39 00:02:27,920 --> 00:02:29,740 We don't really glance at that and say Oh yeah. 40 00:02:29,750 --> 00:02:31,590 That's tracking the document version. 41 00:02:31,640 --> 00:02:34,480 So we are going to make a little tweak to this module. 42 00:02:34,580 --> 00:02:38,720 It's a setting we're not going to update any internal code or anything like that and say rather than 43 00:02:38,720 --> 00:02:44,080 using underscore underscore V We're going to use a field instead called simply version. 44 00:02:44,180 --> 00:02:47,620 Exactly the same as what we've used on all these different diagrams. 45 00:02:47,690 --> 00:02:52,400 So as we save records for our database rather than using the default of underscore underscore V to check 46 00:02:52,400 --> 00:02:56,870 the version we're going to forcibly rename this thing to be simply version and this is going gonna make 47 00:02:56,870 --> 00:03:01,220 it a lot easier for you and I to look at that number understand what it means and eventually take that 48 00:03:01,220 --> 00:03:03,780 number and throw it into any event as well. 49 00:03:03,790 --> 00:03:03,990 Yes. 50 00:03:04,010 --> 00:03:08,930 As you can imagine if we had inside of an event underscoring scurvy not a lot of meaning they're lot 51 00:03:08,930 --> 00:03:13,340 easier to just write out version and immediately look at the thing and say oh yes the version I understand 52 00:03:13,340 --> 00:03:16,760 what that's all about guess that's the idea. 53 00:03:16,790 --> 00:03:22,090 Does your guests are now going to go over to our terminal install Mongoose update if current into our 54 00:03:22,300 --> 00:03:31,980 tickets service so at my terminal I can open up a new terminal window change over to my ticket service 55 00:03:32,700 --> 00:03:40,110 and install Mongoose updates if current while that runs. 56 00:03:40,110 --> 00:03:40,940 We'll take a quick pause. 57 00:03:40,950 --> 00:03:45,510 Come back next video and start to update our ticket service and use this new little module thing.