#2 How to connect mongo DB with node JS || using mongoose in node JS || Learn Node JS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome back to the debug arena in the previous video we have seen that how can we make an api node.js we have made this api this is a basic api which does nothing as of now but through this api we have learned about how how api works how it sends a request and receives a response so now we will make this api dynamic so for that we will use mongodb in this video i am going to show you how can we connect mongodb with node.js so without any delay let's get started now to use the mongodb in your node.js project we have to make an account on mongodb website so go to this website mongodb.com log in there i had already logged in here you can see that currently i am at the dashboard of mongodb now we will make a new project click on new project enter the project name i will enter youtube okay and just click on create project now we have to click here build a database so suppose if you have been logged in for the first time then you will see this screen so you have to continue from here you have to choose the shared and the free one here you have to choose shared here aws choose any location and then click on create cluster now we have to give here username and password so i am giving it [Music] and also remember this username and password okay now i have created the user so you can see here that it is showing this process will take three to five minutes so we will wait for this you can see here that my cluster is ready so now again go to the project i will click on database now our cluster is ready now click on connect here click on choose a connection method and now we have to choose connect your application and you can see here that we are getting this code to copy this code and now come back to your visual studio in that folder okay now that part is done now here we have to install the mongodb so go to a terminal and here install this package mongoose with the help of mongoose we will connect to mongodb from node.js and it is successfully installed now get back to the code now import mongoose so i will write mongoose is equals to require mongoose so i had imported it now what you have to do just go down here now you create a variable name url and paste the url which you have copied and paste it inside the string also you can see here here this is your username and you have to write your password so right i am writing a password here so this step is done now to connect it follow this command mongoose.connect by this we will connect it now you pass that url to which you have to connect and also pass this thing now i will handle it to the promise then and if the connection is successful then it will console [Music] connected to database okay you have to keep it in string okay and if not then it will show us error console.log e so now we are ready to just remove this now we are ready we had written all the code to connect our mongodb to the node.js now save it and start our server so i'm going to cmd norman app [Music] and and you can see here that we are only getting server started and we are not getting connection successful that means that our mongodb is not connected to our node.js let me see what is the error like click on connect okay sorry i forget here to add ip address so you have to click here at inside add a connection ip address you have to click here allow access from anywhere or you can add your device ip address but i prefer this then you have to copy this this might be there as a default and then click on add ip address and just refresh this again go to uh again go to your node.js server you can see that we are getting error just restart the server and you can see here that we are now getting connected to database this means that now our mongodb has been successfully connected to our node.js server so now we can make any type of changes in our mongodb through an api we can insert a user data we can remove a user data we can create a schema and lot of operations so in the next video i will show you how can we create a schema and how can we add a user in mongodb through api that's it for this video and if you found this video helpful then please like share and subscribe thank you [Music]
Info
Channel: The Debug Arena
Views: 15,013
Rating: undefined out of 5
Keywords: how to connect mongo DB with node js, mongoose in node js, node js, mongo db, database, web development, backend in web development, mongoose, backend in node js, learn node JS, react, learn react, react native, MERN developer, learn mern, using express and node, using mongo with express, introduction to mongoose
Id: 8zCZqGLHQQ0
Channel Id: undefined
Length: 6min 41sec (401 seconds)
Published: Mon Jun 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.