MongoDB In The Cloud With Atlas

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey what's going on guys so in this video I'm going to show you how to set up MongoDB Atlas which is a basically allows you to have MongoDB which is a no SQL database allows you to have a deployment within the cloud so that you don't have to have it on your local machine and this video is actually really really important if you've taken my myrn stat course my no js' course on udemy and also a bunch of youtube videos because what I would usually do is use em lab which is a fantastic service same thing you know deployments in the cloud of MongoDB but as you can see right here there's an announcement that M lab is now part of MongoDB so MongoDB Inc has has purchased M lab and if you go to the blog post here basically says that within 12 months you're gonna have to migrate to Atlas ok so this is really important for anybody that's taken my courses that uses M lab so what we're going to do in this video is we're going to set up MongoDB Atlas we're gonna create a cluster add a user stuff like that and then I'm gonna take my dev connector project which is the social network that we build in the myrn stack course which I'll put a link to in the description by the way and then we're going to clone it and I'm going to show you how we can connect to Atlas and there's basically we don't have to do anything extra we just need to change the connection string and it will automatically connect to Atlas alright so what you're gonna want to do is go to MongoDB comm and go up to cloud and choose MongoDB Atlas ok and if you say get started for free it'll take you down to the registration form fill that out I already have an account so I'm gonna go ahead and login okay let's log in here alright so I don't I basically from scratch here you'll see I already build the cluster and stuff but I deleted it so I'm basically starting from scratch you'll be this tat this progress bar will be at 0% for you if you're just getting started but yeah the first thing we want to do is create a cluster okay so we're gonna say build cluster and this may look familiar if you've used em lab before it's just a different UI but same kind of options we want to choose a cloud provider we're going to choose AWS which is the default I'm going to choose North Virginia for my data center cluster tier if you take a look at this we're going to use the free version which is good for development if you're in production then you're probably probably going to want to you know add some some storage and stuff like that but we're going to choose free we don't need any of these additional settings so we're going to keep those the way they are cluster name you can call this whatever you want I'm just gonna call it TM cluster and will say create cluster okay so kind of the same processes M lab I hate these things traffic lights another one alright so one thing I really don't like about this compared to M lab is the amount of time it takes to create a cluster you can see new clusters take between seven and ten minutes so I might actually have to pause the video and with M lab it was literally like 20 seconds but while that's doing that we should be able to create a user so down here you'll see build your first cluster that will get crossed out and then we want to create your first user so we want to go to security and right here add new user and you just want to put in a username I'm just gonna say Brad one-two-three-four both the username and the password and you can choose Alice admin you're probably going to want this here read and write to any day to base and then this one is for read-only so we're gonna keep this selected you can also make them a temporary user if you want to do that and they can expire in a certain amount of time six hours one day one week but we'll just leave that unchecked we'll say add user that you saw already exists I already created that user so let's do one two three four and add user yeah you can see right actually already have that Brad one two three user so these users will as you can see the roles these can write and read any database write two and read from any database and then what you want to do is go to IP whitelist so I actually already have this let me just delete that so you want to add an IP address now there you have a couple options here you can add your current IP address which is which would be your dev machine where you're developing the application and then once you deploy you want to put your server's IP address or you could allow access from anywhere which is what I'm gonna do I'm gonna click that and it'll allow us to connect from anywhere with the username and password but if you're in production if it's a real application for a client I'd suggest just adding your your IP addresses you can also make them temporary just like the users so they would expire in a certain amount of time so let's go ahead and confirm and now we're going to just be able to connect to this this cluster from anywhere if we go to overview looks like it's set up I believe so we should be all set so if we look at our task list here we built the cluster we created the user we whitelisted our IP address which I just I'm accepting all IP addresses they still need the the username and password obviously and then to connect to our cluster we click this connect button right here and it depends on what we want to do if we want to connect through the shell we would click here we want to connect through an application so we would click here you also have a tool called MongoDB compass if you download Hmong ODB locally you'll get this tool called compass which is sort of like like like a PHP myadmin for MySQL like where you can mess with your data stuff like that kind of like a GUI to to interact with your database but what we want is to connect through our application so if we click this it'll show us the screen and we're gonna want the standard connection string okay so if you've taken any of my courses we'll reviews em lab all you would have to do is replace the string with this okay and down here you have some some documentation pages for the node MongoDB driver Ruby Python Java and so on if you want to take a look at that so now that we've created a cluster we've added a user we have our connection string let's let's go ahead and grab the dev connector application and what we need to do here is clone it or you can download the zip whatever you want and then we need to install the dependencies for both the server our Express server and the client which is react and I did create a script to do that but some people have problems with this so I would suggest just seed being into the client folder and running npm install as opposed to doing this and then we set up concurrently to run both the server and the the front-end at the same time with npm run dev and then we just need to create a keys dev file which will have our URI URI string which before was M lab but now we'll put our Atlas string and it should just work fine so let's go ahead and do that so I'm going to bring over my terminal here and I'm just going to do a git clone and let me just grab the string here and it'll paste that in run it it's gonna clone it into a folder called dev connector let's CD into dev connector and I'm gonna open up vs code here okay so as the script says or I'm sorry as the github documentation says we have to add a keys dev file so that goes in the config folder you'll see there's a keys j/s it basically looks to see if it's in production if it is it'll run Keys prod which has our environment variables that would be on the server and if you took the course you know that these are stored in Heroku if not it's gonna load keys dev underscore dev which we don't have so we need to create that so let's say keys underscore dev dot j s and if we go back to github and just grab this right here you have to put that in and the secret can be anything I'm just gonna put the word secret and then the URI is gonna be our Atlas URI so let's go back to Atlas and copy this okay and we'll paste that in and you're gonna want your username which is for me Brad one two three four and then put your password in which is for me Brad one two three four all right and we'll save that so now we should be able to run this we just need to install our dependencies first you can notice that there's no node modules folder and on the server or on the client which is the react app so let's hope let's go ahead and open up our terminal and let's run npm install on the server because we're in the room right now this should create a node modules folder okay so once that's done let's go ahead and CD into the client folder which is react and we're gonna also run npm install and that will set up the react scripts from create react app as well as anything else we used in the course like Axios and i think we used a couple other small modules of course redux and stuff like that and like I said I there is a script npm run client install which will do the same thing it'll it goes into the client folder and runs npm install but i've had some issues with that and some other people have so I think I'm gonna change the documentation sorry about that guys sorry about that alright so let's go ahead and CD back into Express so now we're back in whoops we're back into the root and let's go ahead and run NPM run dev so like I said it runs I don't know if I said it but we're using concurrently it runs the front-end react application as well as the backend server so we should be able to now sign up and then that will get put into a users collection in our MongoDB database in Atlas so let's try it let's sign up and if you're interested in building this application then I'll put a link to my myrn stat course in the in the description it's about a password I will be updating it at some point as well alright so we should be registered let's try to log in here and we'll take a look at Atlas in a second so what did I say Brad at gmail 1 2 3 4 5 6 let's submit and we're logged in ok so once you log in you have a dashboard and it says you have not set up your profile please add some info so we could go ahead and add some info here see I'll say senior developer company website I'm not gonna do let's just do the required feel so skills will say je s PHP oops je s PHP Python and that should be good if you want to add social network network links you can but we're just going to submit that and there we go so now we are in our dashboard we can add experiences which is basically like job stuff like that we can add education and this will all get put into our database so now the fact that it's showing us this means is that it worked but let's double check and go into database here so if we go into our TM cluster and we go to collections we should have we have two collections we have users because remember we registered a user and you can see it right here Brad Travis II Brad at gmail it uses Gravatar for an avatar our hashed password all that stuff profiles we created up a little profile and you can see it has like the skills array it has our handle our status stuff like that so that's it I mean if you're using em lab and any of the projects you created with me or any other project simply switch out the string with with your MongoDB Atlas string and it should just work and like I said I will be updating my courses soon the node J s1 and the node node and express one really needs updating I'll probably do that and then the Martin stat course at the same time I'm also doing HTML CSS course right now which will have like flexbox and the grid system will build a few cool projects so we have that look to look forward to as well but yeah so hopefully you guys enjoyed this if you want to mess around with the dev connector application even if you didn't take the course go ahead and and clone it you can do exactly what I just did we have like posts actually let's do that I will say hello world so we have a post here and if we go back to our database and reload we should see a post collection and there it is hello world alright so hopefully you guys hopefully this is helpful and I will be putting this either in as a video in those courses on udemy or just a link to this video so thanks for watching guys and I will see you next time
Info
Channel: Traversy Media
Views: 190,322
Rating: undefined out of 5
Keywords: mongodb, mongo, mongodb atlas, mlab, node mongodb, mongodb cloud
Id: KKyag6t98g8
Channel Id: undefined
Length: 14min 53sec (893 seconds)
Published: Mon Dec 03 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.