In this video, we dive into CRUD operations using Mongoose with an Express.js app. We’ll show you how to insert multiple records, read data from the database, filter users with specific conditions, update and increment values, and delete documents—all step-by-step. This is perfect for beginners who want to master CRUD operations with Mongoose. Make sure to watch till the end for more video updates and share your feedback!
⌛TIMELINE⏳ 0:00 - Intro to Mongoose + Express CRUD Operations 0:12 - What Did We Learn in the Previous Video? 0:30 - Inserting Multiple Data into MongoDB 2:40 - Reading Data from the Database 5:30 - Finding Users with Age Greater Than 30 7:35 - Updating Students' Data in the Database 10:45 - Incrementing the Age of Students 12:05 - Deleting Students' Documents 13:15 - Recap: What We Learned Today 14:00 - Must-Watch Videos for Beginners 14:25 - Next Video Update 14:40 - Your Feedback on My Video
Hello what's up guys today in this video
we will see Mangus ka operation in our
express application yes guys today's
video is going to be very awesome
because yesterday we completed
how we can basically install Mangus in our express application
How
can we create a connection, we can also create a database,
how do we create a schema,
how do we create models, and then
we basically inserted the data, basically we
inserted a document, I
told you, and at the end we closed it.
So today we will see the complete code operation, so
for that first of all I have another
data, let's fill it in this way,
okay so this data that you are
seeing, it's an array of an object,
inside which there are three such We have a lot of
documents so first of all
I will show you
how you can insert all of them in one go
because in yesterday's video I
showed you that if you want to do a simple insert
then I did it showed the butt What if you
have multiple data like this
and you want to insert it in one go
then how can we do it, so now
step one is to insert in the code operation,
insert comes,
right, here I go If you want, you
can do it this way. I have
different styles of commenting.
So look, we have users,
no matter what, and yes, you wait a second,
I pressed insert, that's why this
happened, so it's wait then. We have users
dot look, if you want you can also write create, there is
no problem but we have insert
and then there is a method in which you
just have to add the user data,
this is it, this is all the
users have to do Do it many and then whatever
an array of an object, whatever multiple data
you are showing, you can do it very easily
only if you do this and do each thing one by one
now I am commenting on
it otherwise whenever I will see this I will run this data
Isn't it so, this document will keep getting inserted
but I don't want to do it, so you
just have to insert this particular data of mine,
basically it is a document,
I will go here, okay, if I
run it then you can see that
Guys so many things are coming to me I mean
this is kind of what I got the idea
I will go here and refresh
and total now I should have four documents
and boom guys this is so
awesome like one you
In yesterday's video we showed you how you could do one
but today we did all three in one go
in Chutki, right?
It's not a big deal, it's easy now let's go to our
step two and that is a read now we You have to
read it. Now here I will tell you multiple
things and I will tell you one more awesome thing.
If you remember, okay let's
read the entire data. So
users, now remember one thing. I have
kept the usage here in small. because
I had to go to Kasol We also have to show you by dialog
what we are reading, okay so we have to
write a
wait and then we have a your dfy, if you remember
directly if I was writing find
then I was not getting the proper data
basically We were getting cursor find so to
show it properly we wrote to array.
Okay, here also I will do the same and
show you. Let's check it out users.
Okay, I am going here and wait a
second, now I will do one thing. This
particular part, I am
commenting on it for a while because then I have to
show the complex data, I have to show only that and
boom guys, now I will zoom it
for you guys, so you can see that
I have got some The data has come in the correct way, look
your first data is fine, this is your second
data and what happened here throw new
error duplicate key error collection aa ok ok
ok the problem is what I
told you whenever you run your application You
do whatever you have written here It
tries to execute it again
now I have inserted many I have looked again
I forgot to comment now what happened is that
our email id is visible this is the advantage of
your schema what have we mentioned in the schema
that our email ID it must be
unique it must be unique so here the same
problem is coming that duplicate error
means that brother
we will not be able to insert the same data again because
we need the email to be unique but this is already
this Email or this or this already exists
so what do we have to do we don't even have to add it
this is the beauty that it is
not letting us add useless data again and again
now let me go here, let me do it for now
hm clear and I run
and that one second one second c2 array is not
a function now I want to tell you one thing
that I had written it intentionally I had
written it intentionally I thought maybe the data would
come but what I mean is This was when you were
working on Mongoose. No now you don't need to
type to array, you don't need to write it at all,
Mongoose is so powerful that it automatically
converts it to array and returns the data to you,
otherwise
how would we get data without to in [ __ ] DB I was not able to
find the
boom guys see how awesome it is look at this it has
come one two this twoti has become 4 how
easily we read it na no it is a bit
complicated so what can I say it
is easy but kind of it may seem a bit tricky to you It
could be so let's for
example we have an age of 35 30 25 and then 31 let's
do one thing, those whose age is more than 30,
you display it, let's
do this query, then it will be fun, okay so I will
go right here,
cost users Now comment on this, it is
not neat, wait look carefully,
wait again we have users do not find,
okay now inside this, first of all
what do you want, A C is greater than 30, so
you will have to write here, as, then you We'll have to
give a column, okay, as and then colon
simple and we have to write it inside the curly braces.
Then, now when you're using any operator, the
comparison operator, now we're
going to apply it here, so I'll again use another
curly braces. I will give you where you will have to pay dollar
and then GT greater than and then again
colon and then write 30 this is it, that's
all you have to do and one thing I
would like to tell you is that if you are
not getting any idea here then I I would
highly recommend that here we
have a course, come to the courses section, it is
fine, the complete web development course,
basically the full stack development course,
ATML CSS JavaScript BOOP 15
Interview Questions of JavaScript
React and Node and Express is still
going on That's why I did not add it, but the
complete Mango DV course is available here.
Here I have told you about A to Z, comparison
operators, logical operators, aggregations,
cursors, indexing, I don't know what all,
I myself have forgotten it, if I tell the truth. But
I have done everything here
with full animations with projects, I highly
recommend it, do check it out once,
I will be very happy, please comment and
share it with friends too, so
we have done a lot of this there, greater than less than
greater than and equal to this, I don't know
how much it was but if you do this, okay,
where earlier I was getting four outputs,
now how many results are coming, let's see
one or two, look, I am getting only two results now
because of this The edge is greater than 31.
Its edge is greater than 30. So it's a 35 and
than 31, both of which are above 30.
I did not get any results. So this is how
awesome it is. So
we have completed our read operation as well. So let's
go with step three where we will see the update
now guys look at this very carefully here
also you guys might find a little trick I mean you might find it
and whenever you go to update then by
setting the dollar, this is the method
you have to use Okay,
after setting the dollar, then how to
write 'const updated' so await, no matter
what users, now pay attention here, now there is no
find sign here, here
simply you do update and one, update
one or even if you just write update, it will work.
Let's check it out what it is. Okay, this is
how we will learn one by one. Yes, there will be
update one. This update will be the main one. Now
let's go for the update. I have made it clear, but
it is an update and update one. Pay attention when
you update. What are you doing first of all what do you
need that which one do I need to update give me some
braces here you will write those things
a unique identification I
mean first of all you have to find out
kind of query you can understand it will
come under this and then The
value with which you want to update will come inside this,
okay, so first of all what do you want to update,
whoever has the email, basically the email is going to be
unique for everyone, so this Bob one, let me
do one thing, or this Bob yes i will
copy it okay so if i email it for one second
then as it is it will work but this This
string should be like this, so if
in my collection user collection,
anyone whose email ID is this, I
want to increase his age by one, okay,
so you will have to write set, then colon and
then again this The method is simple now
what will you do here, the age of it is okay that will
be you can either write h p 1 something like this and leave it
because I don't have any idea
what the judge is right now, I am just telling you,
you can do it in this way You can copy this, let's
paste it and I am commenting on this as well
and I cannot paste that, I want to
paste this,
okay
so guys, you can see it very clearly here
that in this method, we
cannot increment. You can do it and age is not
defined, we are getting it so I will tell you one thing,
when you write the set, then you should
not do this, one second, what is its age,
it is 30, let me make it 32, you can do this.
You can do this okay I'm going here
okay so user dot update is not a
function this is it I wanted to show you that the
update will not happen, it's update one, okay, now there's
no problem, that means now you know
that in Mongoose, you can't just
write update, otherwise you need to write update one and
update many, so I'll go here. I am doing this and
friend this is it acknowledged true modified
one and leave all this match count one okay
modified is done match one means
our work is done so now if I
go here look carefully Bob whose age was
30 now I press ref here, the
value of Bob is 32, so
guys you can update in this way and
you came to know that we need to write update one,
just writing update will not work
but you can do it in your mind You might be wondering can I
increment it. Yes, we
could have incremented it, but
for that I am commenting it out.
Look, dollar set, I
have to set its value. It is evident from the name itself. Now,
we cannot set it. Now baba, I
want an increment, so for that you will have to You will
have to write INC and then again it
is the same thing, edge by one, so now what is happening here is that
you are incrementing this edge by one,
if you write two
then it means whatever is the current A T current judge
plus two increment okay let me just flip
it because right now it's 32 32 will basically
become 37 37 okay so I'm saving control A there's
no other difference
one second yes okay let's go here
alright same thing came It means that
what was 32 a while back, now if I refresh
it will become 37 and today
in this video I showed you how you
can set the update, how you
can increment the value, how you
can decrement it You think for yourself and if you have to
see it then I have already told you how to
find out the decrement so
do check out this video, okay
you will find everything, isn't it so
awesome that we have done code operation through Mango DB
also looked at Now we are looking through Mangoes
and let me know in the comment section whether
you find Mango DV easier
or this one easier, so guys
this is also my work, now let us do this as well
Comment now the last final step fur and that is
to delete okay this is how we can do it now
let's check it out here let me
do one thing I will copy this and
paste it here and
I will see this There is no need for that because
it will be very easy here
because now we just have to delete and
whom to delete will depend on it here,
delete one, okay now I know
that just writing delete will
not work Here delete one and delete many,
okay delete one users and here delete the
deleted
user whoever has the email id,
simple poor guy, with this we have
updated so much, now we are deleting this,
whoever has this email id, delete it. two
now what should the poor guy do now we end or
acknowledge true deleted count one end where
earlier You can see here we have a
total of four documents now at the moment I
refresh now it's your only three
documents because we have deleted the one which was Bob so
guys this is it that's it
for today's video. I
hope you had a lot of fun
because we understood each and every thing with so much love,
we saw each and every thing, I
even made mistakes deliberately at various places so that you can know
that okay this is not this, okay this
is not this, only then we can understand the things I will learn otherwise you will just
copy paste whatever is there and you will never know whether there was an
update, whether there was one update or
many updates, or whether there was any update at all. You are not understanding that to
increment, should I
increment in the set itself, the age is not coming here.
Or the increment is separate, how are you understanding
it, look at this, here the
dollar sign is coming
for greater than, elsewhere the dollar sign has come in this way,
otherwise the more you practice many things, the
more you will You will keep on understanding okay but ya
guys this is it today in this video That's all for you,
I hope you would have liked it very much,
we understood each and every
thing closely, the complete Cud
operation is done, what else is
needed in it, this is mostly used everywhere else,
okay. But if you want to see it in depth, then
I don't know why I am saying this again and again,
but I want it to be
as many views as I have worked so hard for, but
if you watch it once, then
share it with your friends. If you do it, it will help them as well as
you, your
money will be saved and you will also get to learn a
lot, so please do check it
out and tomorrow we will look at the middle
way end Mangu which is very
important, then we will give our URL I will tell you
how you can deal with the short project
and after that finally my
sequel is going to come so it will be fun and
guys if you are still watching this video
then let me know in the comment section that
I will tell you You like it more when I show my face while talking to you,
you like it more openly Are you able to connect with me
through my videos or whatever I
did because I had gone to Nepal and
I did not show my face?
You are more interested in that. It
seems more right to you. There is less
destruction in it. You feel that If it is happening
then let me know in the comment section whether I should
show my face and I mean the one you
can see me now or should I show you my normal self without
camera, please do let me
know by commenting that is also okay and please
subscribe and Next target
is 8 lakh subscribers, my channel is all dependent on you,
okay so please subscribe
and I will meet you in tomorrow's
video till then guys, thank you so much,
take care
[Music]