In this lesson we're going to start the process of deploying the task manager application to production.
Now this was originally going to be a single video and I actually filmed it but it got a bit complex
and a bit long.
So I'm redoing it breaking it up into two lessons in this lesson.
The goal is to get a production ready Mongo DB database and then the next lesson will actually set everything
up on Heroku to get our application deployed and working with that new database.
But as mentioned step number one is to get a production ready database in place.
Right now the only database we have is the one running locally on our machine and that's not going to
work for when we deploy our application to Heroku.
We want to use a mongo D.B. hosting service to get a database up and running that our Heroku app can
connect to.
Now there are dozens of different companies and services that offer Mongo D.B. database hosting and
the Mongo DB organization.
They actually have their own solution called Atlas and that's what we're gonna be using for this class.
So let's get started by heading over to the browser and we're going to work through all of this together
because getting it set up for the very first time can be a little tricky and I don't want to leave you
hanging with the setup process.
So over here in the browser WE'RE GONNA GOOGLE Mongo D.B. Atlas.
This is going to bring us to the Mongo D.B. Atlas home page and it should look something like this.
That's Mongo DB.
Dot com buzzwords slash cloud forward slash Atlas.
Now once again there are plenty of different solutions we could have gone with.
I'm using this one because it's created by the Mongo D.B. organization so everything is always nice
and up to date and they have a generous free tier so we can get started for free forever and then upgrade
when we have a lot of users.
And it actually makes sense right here we're gonna go ahead and get started for free by clicking start
for free and that'll bring us down to a sign up form down below.
Now as mentioned the setup process can be a bit tricky so we'll go ahead and work through everything
together starting by just registering for an account right here.
Let's go ahead and get that done.
I'll pick a password
and then we're gonna go ahead and agree to the terms of service and we'll click get started for free.
Now once again no need to provide anything like a credit card to get started.
You can get started just by creating an account.
We can go ahead and close the little welcome screen and actually dive into the configuration.
Now by default all of the options picked are gonna allow us to stay on that free tier although we could
easily customize things to move into a paid plan.
So we want to be a bit careful when navigating this page making sure we always see free down below.
Now you'll notice terminology related to creating a cluster as opposed to creating a database.
A cluster is nothing more than a Mongo DB database with multiple servers which can allow you to have
a nice low latency around the globe.
So if we scroll down we can pick options such as the cloud provider.
We'll stick with a W S down below that.
We have our regions so we can choose our primary region and currently only 4 actually support the free
tier so you can pick the closest free tier region to you.
For me North Virginia is pretty close.
Down below we have more things we can customize about the tier additional settings and the name.
We're gonna leave all of those at their default value.
We are on what's known as the m 0 plan and that is the free database plan which comes with half a gig
of storage which will be plenty for us as we test and build out our app.
Then in the future we could always upgrade as we start to get paid users.
So down here we're going to create this cluster.
Now the actual process of creating the cluster does take some time.
You're gonna be redirected over to your dashboard page where you're hit with a lot of information all
at once they have a little checklist of things you need to do in order to connect to your database for
the very first time we can just go ahead and minimize that for the moment and in the background.
Our sandbox instance are free tier instance.
This is being created as we speak.
Now this can actually take between 7 and 10 minutes.
So what we're going to do is just cut the video I'm going to wait until the cluster is created and this
Connect button is enabled.
Take some time to wait for that and when you're done just come back and click play
all right.
We're back.
So our instance has been created and we now have some graphs to keep track of statistics about the database.
Now currently there are no connections there are no operations and there's no storage.
So these graphs are particularly useful but these will start to change as we actually connect read and
write and store data.
Now on the left hand side in order to get started what we need to do is click this Connect button.
This is going to walk us through a little one time setup for this particular cluster.
So right here we're seeing a warning.
You can not connect yet set up a firewall access and use your security permissions below.
So we just have to work through this page.
It's really short.
Then we'll be ready to actually connect to the database both from a gooey and from Visual Studio code
in our project.
So right here let's go ahead and add a different IP address and we're going to provide the following.
That's zero dot 0 0 0 forward slash 0.
This is going to white list all eyepiece.
That's going to be our IP for your local network.
And that's also going to allow this database to be connected from the Heroku because Heroku is going
to change that IP over time.
And we want to make sure we can always connect when it comes to security.
Don't worry we will have a user name and password as well which we'll be configuring down below.
So with this in place for the IP address we can go ahead and click Add IP address which is going to
add it and we can see we've completed one of those steps over here and the next thing to do is to create
a database user.
This is someone who can connect to the database and we're gonna go ahead and pick something that makes
sense for us.
I'll go ahead and say task app as my user name and then I'll also go ahead and provide a password when
you provide the password.
Take a moment to write it down or remember it as this is going to become important in a couple of seconds.
You can always use the Atlas interface to get the password you set later on but we don't want to have
to go back and forth between all the windows.
So right here we're creating the first user for the database which will have access.
We're going to go ahead and click Create Mongo DB user and that's gonna be it for this page.
The next thing we can do is actually connect to the database.
And right here if we continue on to the next step in our little three step wizard it is choose a connection
method and we have three options available connecting from the terminal connecting from our application
or connecting from what's called Mongo D.B. encompass Mongo DB compass is Mongo D BES official gooey
tool.
So it's similar to robo 3D though it's released and maintained by the Mongo DV organization itself.
Now we're actually going to take a quick moment to switch over to mongo DB compos as robo three ti currently
cannot connect to mongo D.B. Atlas databases which is obviously a problem for us.
Hopefully they address that in the future but for the moment we'll just switch to this other gooey.
It's also free available for all operating systems and we can get started right away just as easily
as we were able to with robo 380 and they do the exact same thing and allows us to see and manage our
data.
Right here I'm going to go ahead and grab the download for my operating system that's going to start
the installation process well more like the download process and once it's downloaded we're gonna take
a quick moment to set it up connecting to those two databases one to our local host database and then
two to our Mongo D.B. Atlas database.
Now down below it's showing us to the connection string options we have available.
We are going to go ahead and use this first one that is compass one point 1 2 or later.
And down below we have the connection string which we will eventually copy to the clipboard.
But before we get ahead of ourselves let's go ahead and just get Mongo DB compass setup now like with
all software programs the installation process will be different depending on what OS you're running
on.
For me on a Mac I just need to take the application and drag it over to the applications directory from
there.
I'm going to open the applications directory and we're actually going to boot the program up so I'll
scroll down to M for Mongo D.B..
And the program is called Mongo D.B..
Campus community so the community addition is there free edition and that we'll be able to access right
now.
I'm going to go ahead and crack that open and we'll take a quick moment to connect to our local host
database first.
Right here it's asking me if I do want to run this software from the Internet.
Of course I do.
And then we're gonna be brought to the Mongo D.B. campus community application now right here we have
a quick since agreement to agree to and then will be brought to a quick wizard.
We can close that down as we'll work through the setup process together.
We can choose if we want to send those statistics and crash reports.
I always do.
And now we are at any connection screen now by default.
All of the information here.
All of those default values they're going to allow us to connect to the local host database.
It's already local host on Pt. 2 7 0 1 7 so down below we actually don't need to fill or change any
of these fields.
All I'm going to do is pick a favorite name for this one and I will choose local host Mongo D.B. database.
I'm going to create that as a favorite so I can easily connect to it from right here and then we'll
go ahead and click connect to connect to our local host database.
Right here we have the task manager API.
We have our tasks and users collections and we could crack those open to see the data exactly like we
would be able to in robo 3 T.
So right here I have the documents.
I can also view them in a table view and once again I can manipulate the data.
Insert new documents.
Search the documents and do anything else I'd want to know that this is working.
Let's go ahead and connect to the production database as well so up above what I'm going to do is go
to connect and then I will disconnect from the local host database.
That brings us back to the connection screen and we're going to go ahead and create a new connection
over here in the sidebar.
Now we do have to fill out all of these details and the information we'll be using is information that's
stored in that connection string over in the browser.
So this contains the data we need.
Now it does not contain the password.
But we can go ahead and get started.
What I'm going to start with is just grabbing this right here.
The host.
That is what's after the at sign all the way up to mongo D.B. dot net.
I'm going to copy that to the clipboard.
I'm gonna head back over to Mongo DB compass and paste it in right up top.
Now when it comes to the port we do want to go ahead and stick with the standard port.
And I do want to enable s r v record which we'll talk about in just a little bit down below for authentication
we do have to authenticate and we'll be using a user name and password combination right here.
We have to provide that user name and password we created in that little setup wizard when we clicked
that connect button.
So for me I had called it task app and then I set up my password.
And this is the one that I told you you need to remember for this step down below that we have our authentication
database.
We're going to leave that as is.
We have other information which we don't need SSL that's already set up correctly for Atlas deployment.
SS H tunnel none.
And then down below that our favorite name.
So for this one I could pick something like a production Mongo D.B. database.
I can create that as a favorite.
And then we can go ahead and connect to that as well.
Now when we connect we're not going to see our data because we haven't created any collections and we
haven't inserted any documents but we will get to that in the next video when we finalize the deployment.
For the moment the goal is to just make sure we can actually connect it to the database from outside
of the Web site.
So whether it's from the composite application or from our project in Visual Studio code.
So here we can see that we were able to connect successfully.
Now there is no task manager api database showing up but that will change when we actually connect and
create the database from our application in the next lesson.
So now we can go ahead and disconnect from this as well and we can use Mongo DB compass in the future
to manage our data either locally or in production.
So over here on the left hand side that means we no longer need robo three TI.
We can go ahead and close that program down.
Now there are two quick things I want to talk about first up S.R. v records.
Those come from the DNS world.
They are not specific to mongo D.B. Mongo D.B. Atlas or compass in any way whatsoever.
That is what maps this right here the host to the correct IP and port.
And down below if you forgot the password you created for your user.
You can use the web interface to actually find it.
So over here we're actually done with this whole little modal showing us how we can connect.
We can close that down and start to manage our data from the interface.
What we're going to do is head over to security and here we have Mongo D.B. users.
This contains that user we created in that little setup modal.
We also have IP whitelist over here.
This is where the IP we set up now lives.
Let's go ahead and go back to Mongo DB users will go to edit we'll go to edit password.
Then you can click Show to view the password that you created for your user.
You can then use that when connecting from Mongo DB compass.
If you forgot what the password was.
So now that we have this in place we have a production ready database and we're able to connect to it
from a gooey tool in the next lesson.
We're going to focus on getting everything set up on Heroku.
We need to create the Heroku application.
We need to figure out how to set up environment variables on Heroku and then we need to deploy our code.
I'm really excited to get to that.
So let's go ahead and jump right in to the next lesson.