Complete MongoDB Tutorial #25 - MongoDB Atlas

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right then my friends so we have made now this node and express api which communicates with mongodb locally on our computer now when it comes to a production application your app won't be communicating with your local mongodb service but instead with a mongodb server online and one way to do that is to use something called mongodb atlas which is a database as a service platform and it allows you to set up a free tier cloud database really easily that you can just then hook up to your application in just a few minutes so the first thing you want to do is head to mongodb forward slash atlas and you want to sign up for a free account or just click on this try free button right here and that's going to ask you to sign up for an account or sign in with google which is what i'm going to do because i already have an account so i'm going to click on that but sign up this way if you prefer and then once you've done that it's eventually going to bring you to your dashboard where you can create databases so it's going to look something like this so i'm going to build a database so let's click on this and then we get three different options now i'm going to go with the shared one which is free right here so click on create and it's going to ask you a few options so first of all the cloud provider which i'm going to stick with aws for and then the region right here now i'm going to stick with the default but you can change that if you wish if you scroll down you can change the cluster name if you want to as well i'm going to stick with the defaults and just create the cluster now when you do that it's going to take a few minutes to create that and it says that down here but while we do that you can create a username and a password and that's going to be used to connect to your database from the code now i've already created a username and password and i'll show you that if i go to database access over here you can see i've got two users and i'm going to use this one right here yoshi and i already created a password which was test123 so you can add that username by filling in those form fields a minute ago and then clicking add or you can go to database access and you could add a new database user right here and you can create it here okay so you need to do that also you need to go to network access and you need to allow access to the database from our computer basically or some other network so i'm going to add ip address and then i'm just going to say allow access from anywhere now you can add your current ip address if you want to which will give you access from your computer i'm going to allow access from anywhere for now but make sure that when you go into production that you don't allow access from anywhere otherwise anyone can access the database and do what they want with it so let's not do that in production let's just do this for testing so i'm going to confirm this and that's just going to take a second as well and then if you go back to database then it probably won't have been created just yet so just hang fire for a couple more minutes all right then so when it's created we can click on this connect button right here to get our connection string so we want to connect our application so click on this and you can see this is the connection string right here the only thing we need to do is replace this with our username that we created and this with the password so i'm going to copy this right here and head back to my code all right then so now back inside the db file all we need to do is replace this connection string right here with the one we just copied so let's delete this and paste in this other one now because this is quite long what i'm going to do is create a new variable up here called uri and i'm going to set that equal to this string like so and then i can just pop the uri variable in here and that looks a bit better so that's all we need to do in our code except we need to also add the username and password right here so i'm going to use yoshi which was the username i created and the password was test1234 and by the way don't try connecting to mine because by the time you watch this tutorial this is not going to exist all right so i'm going to save that now and now we're going to try making requests to this database from postman okay then so in postman we don't actually have to change any of these requests because we're still making requests to localhost which is where our node api is running it's just that in our node api now we're communicating with the mongodb atlas instead of a local installation of mongodb however if i do try to make a request to get all books then obviously we won't get any back because we don't have any books stored inside the mongodb database online however we can't create them so let's open up a post request that we had saved before and if we go to the body we already have all of this book data that we used last time so i'm going to make a post request to add this book so let me send this and see if we get a response and we can see now we get an inserted id and acknowledged is true so hopefully fingers crossed this has worked if i go to this request now to get all the books hopefully we should see that one book come back which we do so that has worked now what i'm going to do is add another book over here i'm just going to change this to the way of kings i'll keep all the rest the same just for simplicity i'm going to click send and we can see that's been added as well and now if we try to get all books again this time hopefully we'll see two books the first one and the second one awesome and also in atlas if you go to browse collections you're now hopefully going to see a new collection called books you can see this right here and down here we can see the two documents so that has all worked so then now we have our database up and running online with mongodb atlas and that was really really simple to do and that my friends is unfortunately the end of this mongodb series now in the future i will also be making a mirn application playlist to show you how to create a full stack application with mongodb node express and react and maybe i might even do a few tutorials about mongodb realm which is a feature-rich development platform for building mobile web and desktop applications and it includes services like authentication serverless functions a database and real-time data synchronization so definitely stay tuned for that so my friends i really really hope you enjoyed this series and you learned something along the way if you did please please please don't forget to share subscribe and like that really means a lot and if you want to access all of my youtube courses without adverts also get access to premium courses and early access courses as well you can do at netninja.dev you can sign up for net ninja pro which is just nine dollars a month and also half price for the first month with this promo code right here and for that like i said you get access to every course without adverts without youtube adverts you also get access to exclusive courses not found anywhere else you get access to my premium courses on udemy and also early access to all of my youtube courses as well so the link to this page to sign up is going to be down below again i really hope you enjoyed this series and i'm going to see you in the very next one [Music] you
Info
Channel: Net Ninja
Views: 106,238
Rating: undefined out of 5
Keywords: mongodb, mongo db, mongo, mongodb tutorial, mongo db tutorial, mongo tutorial, tutorial, node api, mongo node, mongodb node.js, mongodb node, node tutorial, mern app, mern, mongodb api, install mongodb, mongodb atlas, atlas
Id: 084rmLU1UgA
Channel Id: undefined
Length: 7min 23sec (443 seconds)
Published: Thu Apr 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.