1
00:00:00,450 --> 00:00:00,750
Okay.

2
00:00:00,750 --> 00:00:06,720
So in this lesson, we're going to set up our MongoDB database using MongoDB Atlas, which is a cloud

3
00:00:06,720 --> 00:00:10,770
version, meaning you don't have to install Mongo on your local machine.

4
00:00:10,770 --> 00:00:14,750
And then when we deploy, you don't have to install it on your your dev.

5
00:00:14,790 --> 00:00:16,560
I'm sorry, your production server.

6
00:00:16,560 --> 00:00:19,440
So you just need to go to Mongodb.com.

7
00:00:19,440 --> 00:00:23,100
It's completely free for the plan that we're going to be using.

8
00:00:23,100 --> 00:00:28,950
Obviously if you have a larger production app, you're going to want to pay for your services, but

9
00:00:28,950 --> 00:00:33,090
they do have a very generous free tier for testing and for small projects.

10
00:00:33,090 --> 00:00:38,190
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,

11
00:00:38,190 --> 00:00:39,540
you're just going to log in.

12
00:00:40,460 --> 00:00:41,870
I'm going to do right now.

13
00:00:41,870 --> 00:00:44,510
And and I have multiple accounts.

14
00:00:44,510 --> 00:00:47,900
This one I cleared out for specifically for this course.

15
00:00:48,320 --> 00:00:52,460
So you're going to have to create, most likely create an organization.

16
00:00:52,460 --> 00:00:54,500
I already have one called Traversy Media.

17
00:00:54,500 --> 00:00:56,390
And then you can create a project.

18
00:00:56,390 --> 00:00:58,580
So we'll call this pro shop.

19
00:01:00,010 --> 00:01:02,590
And then if you have other members, you can add them.

20
00:01:02,590 --> 00:01:05,230
But it's just me, so I'm going to click Create Project.

21
00:01:06,630 --> 00:01:10,140
And then we should be able to create our database cluster.

22
00:01:10,800 --> 00:01:15,450
So if you see this screen, don't worry about this current IP address not added.

23
00:01:15,450 --> 00:01:16,500
We'll do that in a minute.

24
00:01:16,500 --> 00:01:25,290
But just click on build a database and we're going to choose the M0 free option and AWS will use that

25
00:01:25,290 --> 00:01:28,590
as the provider and then we can click Create.

26
00:01:28,620 --> 00:01:31,530
Now this is where you're going to add your database user.

27
00:01:31,530 --> 00:01:34,560
So and this is different from your MongoDB user.

28
00:01:34,560 --> 00:01:41,010
So I'm going to use Brad one, two, three for the username as well as the password.

29
00:01:41,280 --> 00:01:42,990
And then make sure you click this button.

30
00:01:42,990 --> 00:01:50,910
I know it's easy to miss, so from here you want to add your IP address, so it should actually be added

31
00:01:50,910 --> 00:01:51,810
automatically.

32
00:01:51,810 --> 00:01:53,100
And this is my VPN.

33
00:01:53,100 --> 00:01:58,530
I'll probably blur it out anyways, but it should get added automatically.

34
00:01:58,530 --> 00:02:03,120
If it doesn't, then just click this button right here and it will add your address.

35
00:02:03,330 --> 00:02:03,750
Okay.

36
00:02:03,750 --> 00:02:08,490
So then we can click finish and close and then go to databases.

37
00:02:08,490 --> 00:02:10,630
And then you should see a screen like this.

38
00:02:10,630 --> 00:02:12,730
Now to get our connection string.

39
00:02:12,730 --> 00:02:15,550
If you click on Connect, there's a couple options here.

40
00:02:15,550 --> 00:02:21,700
So we want this connect to your application and this is the string that will use from our application.

41
00:02:21,700 --> 00:02:23,050
So let's copy that.

42
00:02:23,050 --> 00:02:27,070
And then what we're going to do is put that into an environment variable.

43
00:02:27,070 --> 00:02:36,100
So in the dot env file, let's say Mongo underscore Uri and let's set that to that connection string.

44
00:02:36,100 --> 00:02:38,260
Now there's a couple of things we need to change here.

45
00:02:38,260 --> 00:02:40,210
For one, we need to add the password.

46
00:02:40,210 --> 00:02:43,840
So whatever you used as a password, go ahead and add that here.

47
00:02:43,840 --> 00:02:48,100
And don't worry, this is only on the server, this isn't displayed on the client, so people aren't

48
00:02:48,100 --> 00:02:49,630
going to see this or anything.

49
00:02:49,630 --> 00:02:56,350
And then also after the slash, if we don't put anything, it's going to use a database called test.

50
00:02:56,350 --> 00:03:00,610
And I actually want to have our database called Pro Shop.

51
00:03:00,610 --> 00:03:02,830
So we're just going to add that there.

52
00:03:03,130 --> 00:03:03,550
Okay.

53
00:03:03,550 --> 00:03:05,740
And then we'll save that.

54
00:03:05,740 --> 00:03:12,960
Now let's come back over here and click on Browse collections and if we had data in here, you'd be

55
00:03:12,960 --> 00:03:13,800
able to see it.

56
00:03:13,800 --> 00:03:14,670
But we don't.

57
00:03:14,700 --> 00:03:20,580
However, I'm going to say add my own data and then for the database name we're going to say pro shop

58
00:03:20,580 --> 00:03:25,140
because that's what I put in the connection string, and you can add a collection as well.

59
00:03:25,140 --> 00:03:27,960
So for now, let's just add our products collection.

60
00:03:28,640 --> 00:03:30,170
And then click Create.

61
00:03:31,470 --> 00:03:37,950
So now we have a database called Pro Shop with a products collection, and you don't have to manually

62
00:03:37,950 --> 00:03:42,720
add your collections through the interface with with NoSQL databases like this.

63
00:03:42,750 --> 00:03:45,510
You can create them through your application.

64
00:03:45,510 --> 00:03:51,240
So we didn't actually have to create this collection now, but I did want to specify the database name.

65
00:03:52,100 --> 00:03:52,640
All right.

66
00:03:52,640 --> 00:04:00,120
So I think that's pretty much it as far as what I want to do right now in this video.

67
00:04:00,140 --> 00:04:02,170
Make sure your dot git ignore.

68
00:04:02,180 --> 00:04:07,670
Make sure you have the dot env file in here because you don't want to push that to your repo.

69
00:04:07,700 --> 00:04:16,399
What I would suggest doing is creating something like a let's say example dot env and then you could

70
00:04:16,399 --> 00:04:21,079
push that and just have the actual variables but without the values.

71
00:04:21,079 --> 00:04:22,820
So I could do this.

72
00:04:22,820 --> 00:04:25,610
I mean these two really don't matter, but this one.

73
00:04:26,440 --> 00:04:28,480
He would say something like Add.

74
00:04:29,430 --> 00:04:30,450
Add.

75
00:04:31,080 --> 00:04:32,220
Your.

76
00:04:33,660 --> 00:04:36,420
Uh, Mongo, Uri or something like that.

77
00:04:37,670 --> 00:04:37,970
Okay.

78
00:04:37,970 --> 00:04:38,390
Just so.

79
00:04:38,390 --> 00:04:44,270
Just so if other people are going to use this application, they know which variables they need, then

80
00:04:44,270 --> 00:04:46,580
they can just rename this to dot env.

81
00:04:47,670 --> 00:04:48,060
All right.

82
00:04:48,060 --> 00:04:49,350
So that's all we're going to do here.

83
00:04:49,350 --> 00:04:54,960
And the next video, I want to show you how we can connect to our database using a tool called Compass

84
00:04:54,960 --> 00:05:02,040
so that if you need to get directly into your database to read or create data or update data, you can

85
00:05:02,040 --> 00:05:03,390
do that very easily.

