All right my friends let's implement all this concurrency control stuff inside of our tickets service.
First we're gonna first focus on building out all these virgin stuff inside of our ticket service or
then going to make sure that all the versioning numbers and whatnot get reflected inside of all these
different events so eventually Mitt and we'll eventually move over to our order service and make sure
that the order service makes use of the Virgin stuff as well.
So ticket service first we're going to take a look at a little module that we're going to use along
with Mongoose to handle all diverting stuff for us.
We're gonna start to write out a test or two to make sure that it all works as we expect.
So let's let me first show you some documentation on a module that we're going to use at NPM J Ask.com.
We're going to look up a module called Mongoose update if current so here it is right here.
If you want to you could certainly take a look at the documentation.
It's actually some pretty fantastic documentation.
It explains what it does.
Pretty easy and straightforward.
You will notice if you read the documentation that this thing can implement Optimistic concurrency control
either by using a version number or by using a timestamp.
So like an actual date time when the record was last updated that we're gonna go with the strategy of
using a version as opposed to a timestamp.
So we're gonna be doing inside of our app if you want to you again Take a look at the documentation
here.
It's really easy to get started with pretty much all we have do is imported wired it up to our schema
the schema that we want to use this versioning stuff on and then the one reason I'm kind of showing
you the documentation here just a little piece of trivia.
You'll notice that if we're going to use this version no thing so version 1 version 2 version 3 and
so on the version is gonna be set on the underscore underscore the property of the Mongoose document.
So chances are you've seen that underscore underscore a V thing before with logos even if we take a
look at say our postman that we've been using.
Let's see if I can log in here really quickly.
Come on I want to show you one log me in and then post a ticket.
There we go.
Finally there we go.
Finally.
So you can see underscoring ASCII score the right there.
That is the version number that Mongoose implements by default but right now there's nothing to actually
incremented nothing to say make use this value.
Make use this flag or anything like that by default Mongoose update of current.
That's the module we're using is going to try to use that underscore underscore the property for checking
the version now for you and I underscoring the scurvy doesn't really have a lot of meaning.
We don't really glance at that and say Oh yeah.
That's tracking the document version.
So we are going to make a little tweak to this module.
It's a setting we're not going to update any internal code or anything like that and say rather than
using underscore underscore V We're going to use a field instead called simply version.
Exactly the same as what we've used on all these different diagrams.
So as we save records for our database rather than using the default of underscore underscore V to check
the version we're going to forcibly rename this thing to be simply version and this is going gonna make
it a lot easier for you and I to look at that number understand what it means and eventually take that
number and throw it into any event as well.
Yes.
As you can imagine if we had inside of an event underscoring scurvy not a lot of meaning they're lot
easier to just write out version and immediately look at the thing and say oh yes the version I understand
what that's all about guess that's the idea.
Does your guests are now going to go over to our terminal install Mongoose update if current into our
tickets service so at my terminal I can open up a new terminal window change over to my ticket service
and install Mongoose updates if current while that runs.
We'll take a quick pause.
Come back next video and start to update our ticket service and use this new little module thing.