Right here you can see that we are sending the guitar to the database using this exact pushed method.
Now what we need to do is let's go to our summer file.
So we go to our server file which is in the control the private chat digests so right here inside this
chat post-speech that is the post route we have to create a noon function but we are going to use the
waterfall instead.
We are going to use a sync dots parallel so to do that.
So we are a sync not parallel shoes right.
I believe you understand how this works.
The next thing we want to do is we then Estyn is our creative function.
Passing Colback now inside a function we're going to check if requests Dotts body Dadds charts ID.
Let's go to the view so inside of view message dot Aegeus you can see right here we have these attributes
this input feud with NAME attribute chart ID.
So if request that body that chart ID we want to update the message collection.
So we're going to search through the message collection look for the data that the ID is equal to the
ID coming from the body.
So this is going to be message dot updates because we've been using the updates.
You should understand how this works.
So Messud dot updates inside with passen objects.
The first thing we want to do is we want to get the documents that the idea is to request doats body
dots chats ID so inside the message collection we're going to look for the documents that ID is equal
to request what body or chart ID because this request would put it or chart IDs coming from the view.
Then the next thing is we are going to updates.
We want to audit the is red field.
So inside we look for the future.
The property code is red.
Let's go to modals message.
You can see here we have this property called is red.
So we've got two sets for the property inside that document.
Then we are going to set it equal to two by default it is set to false.
So when we are it's when the user clicks on that value then this message will be set to to then the
next thing I want to do is let me just add the callback.
So this is going to be a row.
Then it can pass the value so it's good to show us if the document was updated.
So let me do a call schulle not log.
Then I'll pass don't call back.
It's a rule don't.
Then the question is right here let me add to the rest don't redirect.
So I can copy this one on I have here.
So because we want to redirect the user so it's good to be addressed.
Don't redirect.
We're passing in this not we have now only have this a single parallel.
It's going to check if the records body don't Chawton ID is available then it will go into the message
collection look for the document.
Whose idea Sokoto requires a body or chart ID inside a document.
It's going to look for the property code is red then it's updated to try to set it equal to true.
Then we pass in this callback.
After that we redirect the user.
So now that we have this what we just need to do is let's go to the browser to test this out.
If it's successfully updated then we are going to see some values inside the console.
So let's go right here.
Let me refresh the speech.
So if I click on this let me click on the second user.
So if I click on this right now you can see that the value has been decremented by one to show that
that message is read property sets equal to true.
So if I go down here you can see this property right here.
That's a document has been updated.
So if I go back here then for this user if I click on the user then it will take me to the speech.
Now we don't have any documents or we can see the messages.
So if the user sends a new message they may send a new message first let me click on this and see what's
sop then saying he'd send you back to this user.
Now if I click here you can see we have the message.
Now it has taken us to this user speech and the value has been reduced.
So what we need to do is if we want this option out if you want you can go to your JS file which is
message link or just right here.
You can do something after this.
Jack Smith told you can decide to Emmets the new events sockets not Emmets.
Then I Kandace images and refresh
so I can go here then you copy.
You can copy this places inside here.
Then you pass it into this image.
Metod So what you Emmets as we have usually don't you don't go into the Savar file listen for events
then and myths and new events come back to this fae to listen for events.
That is if you want to refresh the page.
But as you can see because this link was click on it it's going to take us to another page.
It is going to automatically refresh.
So right here I can take this.
So I say it's totally optional.
You can decide to do it on your own you if you want to see how you can emit and or event or maybe you
will do something different.
You can meet an event from here.
So as we have it right now what's the message comes in.
A user can click on it then it's going to reduce the value.
If we go to the message collection the limb may search for this.
Now you can see these documents.
We have this is red property set to true and we are only displaying the values that the property is
set to false.
So let's go to Parshall's message that Aegeus right here.
You can see we are looking through the charts I read they were saying if not at index ID or body that
is red is equal to false then increment this value we have here by one.
So any document or any object was Israel property set to true.
It's not going to be added or the this value will not be incremented rather it will be reduced by one.
So right now you can see we have this working what we are going to do next is we are going to see how
we can add these values if we go to our homepage how we can add enough to our home and also add enough
to this group page.