Okay.
So in this lesson, we're going to set up our MongoDB database using MongoDB Atlas, which is a cloud
version, meaning you don't have to install Mongo on your local machine.
And then when we deploy, you don't have to install it on your your dev.
I'm sorry, your production server.
So you just need to go to Mongodb.com.
It's completely free for the plan that we're going to be using.
Obviously if you have a larger production app, you're going to want to pay for your services, but
they do have a very generous free tier for testing and for small projects.
So what we're going to do is or what you're going to want to do is sign up, okay, Once you sign up,
you're just going to log in.
I'm going to do right now.
And and I have multiple accounts.
This one I cleared out for specifically for this course.
So you're going to have to create, most likely create an organization.
I already have one called Traversy Media.
And then you can create a project.
So we'll call this pro shop.
And then if you have other members, you can add them.
But it's just me, so I'm going to click Create Project.
And then we should be able to create our database cluster.
So if you see this screen, don't worry about this current IP address not added.
We'll do that in a minute.
But just click on build a database and we're going to choose the M0 free option and AWS will use that
as the provider and then we can click Create.
Now this is where you're going to add your database user.
So and this is different from your MongoDB user.
So I'm going to use Brad one, two, three for the username as well as the password.
And then make sure you click this button.
I know it's easy to miss, so from here you want to add your IP address, so it should actually be added
automatically.
And this is my VPN.
I'll probably blur it out anyways, but it should get added automatically.
If it doesn't, then just click this button right here and it will add your address.
Okay.
So then we can click finish and close and then go to databases.
And then you should see a screen like this.
Now to get our connection string.
If you click on Connect, there's a couple options here.
So we want this connect to your application and this is the string that will use from our application.
So let's copy that.
And then what we're going to do is put that into an environment variable.
So in the dot env file, let's say Mongo underscore Uri and let's set that to that connection string.
Now there's a couple of things we need to change here.
For one, we need to add the password.
So whatever you used as a password, go ahead and add that here.
And don't worry, this is only on the server, this isn't displayed on the client, so people aren't
going to see this or anything.
And then also after the slash, if we don't put anything, it's going to use a database called test.
And I actually want to have our database called Pro Shop.
So we're just going to add that there.
Okay.
And then we'll save that.
Now let's come back over here and click on Browse collections and if we had data in here, you'd be
able to see it.
But we don't.
However, I'm going to say add my own data and then for the database name we're going to say pro shop
because that's what I put in the connection string, and you can add a collection as well.
So for now, let's just add our products collection.
And then click Create.
So now we have a database called Pro Shop with a products collection, and you don't have to manually
add your collections through the interface with with NoSQL databases like this.
You can create them through your application.
So we didn't actually have to create this collection now, but I did want to specify the database name.
All right.
So I think that's pretty much it as far as what I want to do right now in this video.
Make sure your dot git ignore.
Make sure you have the dot env file in here because you don't want to push that to your repo.
What I would suggest doing is creating something like a let's say example dot env and then you could
push that and just have the actual variables but without the values.
So I could do this.
I mean these two really don't matter, but this one.
He would say something like Add.
Add.
Your.
Uh, Mongo, Uri or something like that.
Okay.
Just so.
Just so if other people are going to use this application, they know which variables they need, then
they can just rename this to dot env.
All right.
So that's all we're going to do here.
And the next video, I want to show you how we can connect to our database using a tool called Compass
so that if you need to get directly into your database to read or create data or update data, you can
do that very easily.