Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,160 --> 00:00:04,580
All right, as a final step in this section,
2
00:00:04,580 --> 00:00:07,880
let's now connect our remote hosted database
3
00:00:07,880 --> 00:00:11,603
with our Compass app and also with the Mongo shell.
4
00:00:13,040 --> 00:00:15,030
So back here in the Atlas app,
5
00:00:15,030 --> 00:00:17,890
let's open up the Connect assistant
6
00:00:17,890 --> 00:00:20,220
by clicking this button here,
7
00:00:20,220 --> 00:00:22,320
and so now before we can actually connect,
8
00:00:22,320 --> 00:00:24,000
we need to do a couple of things.
9
00:00:24,000 --> 00:00:27,023
First up, we need to add our current IP address,
10
00:00:28,210 --> 00:00:31,540
just like this, so that our computer is actually able
11
00:00:31,540 --> 00:00:35,310
to connect to this cluster, okay?
12
00:00:35,310 --> 00:00:38,150
Next up, let's create a username.
13
00:00:38,150 --> 00:00:39,920
And I'm calling mine simply Jonas,
14
00:00:39,920 --> 00:00:43,510
and then a password, which I'm gonna autogenerate here.
15
00:00:43,510 --> 00:00:44,930
And I'm actually showing it to you now
16
00:00:44,930 --> 00:00:48,900
because I need to copy it, but don't try to connect
17
00:00:48,900 --> 00:00:51,550
to my database using this password,
18
00:00:51,550 --> 00:00:53,040
because of course I'm gonna change it
19
00:00:53,040 --> 00:00:54,600
by the end of the course.
20
00:00:54,600 --> 00:00:56,750
Now where am I gonna save it?
21
00:00:56,750 --> 00:00:59,400
Well, let's go to our application
22
00:00:59,400 --> 00:01:01,860
and open up our config file.
23
00:01:01,860 --> 00:01:03,330
And so this is what we created
24
00:01:03,330 --> 00:01:05,343
this file for in the first place.
25
00:01:06,570 --> 00:01:09,720
Right, so remember how we said that each configuration,
26
00:01:09,720 --> 00:01:11,980
we were gonna save into this file,
27
00:01:11,980 --> 00:01:13,670
and so the database password
28
00:01:13,670 --> 00:01:15,763
is actually a perfect example for that.
29
00:01:18,430 --> 00:01:19,423
So database,
30
00:01:21,170 --> 00:01:22,870
password and I'm setting it
31
00:01:22,870 --> 00:01:25,120
to the password that we just created.
32
00:01:25,120 --> 00:01:27,890
And later, when we will then connect our application
33
00:01:27,890 --> 00:01:30,310
to the database, we will then of course use
34
00:01:30,310 --> 00:01:34,663
this environment variable to create that connection, okay.
35
00:01:36,620 --> 00:01:39,710
So, let's now create the user actually.
36
00:01:39,710 --> 00:01:42,120
And now next up, all we have to do is to choose
37
00:01:42,120 --> 00:01:44,470
a connection method and we're gonna start
38
00:01:44,470 --> 00:01:47,710
with the MongoDB Compass application.
39
00:01:47,710 --> 00:01:50,550
Okay, so we already have Compass,
40
00:01:50,550 --> 00:01:54,670
and I'm sure we have a 1.12 or later
41
00:01:54,670 --> 00:01:59,090
and so let's now go ahead and copy this connection string.
42
00:01:59,090 --> 00:02:02,143
Okay, and now open up Compass.
43
00:02:02,980 --> 00:02:06,050
Then up here, in the menu, hit connect here.
44
00:02:08,139 --> 00:02:10,977
Then it will take some time to open up this new window.
45
00:02:13,570 --> 00:02:16,440
But by the time it does, it will then have automatically
46
00:02:16,440 --> 00:02:19,440
detected that we have a MongoDB connection string
47
00:02:19,440 --> 00:02:21,780
in our clipboard, and so all we have to do
48
00:02:21,780 --> 00:02:24,810
is to hit yes here and it will then automatically
49
00:02:24,810 --> 00:02:27,250
fill all of these settings for us.
50
00:02:27,250 --> 00:02:31,200
So our hostname our username and all this other stuff.
51
00:02:31,200 --> 00:02:34,163
And so all we need is our password here.
52
00:02:35,400 --> 00:02:38,870
So I'm going back to that file, grab it from there,
53
00:02:38,870 --> 00:02:41,500
paste it here, and connect.
54
00:02:44,210 --> 00:02:46,810
And indeed, it did successfully connect,
55
00:02:46,810 --> 00:02:49,140
now it's loading our databases.
56
00:02:49,140 --> 00:02:52,370
And here we actually see the three database that
57
00:02:52,370 --> 00:02:55,500
already come pre-configured in this cluster.
58
00:02:55,500 --> 00:02:58,393
So let's create a new one called natours.
59
00:03:00,600 --> 00:03:03,470
And we also have to create a collection name right away,
60
00:03:03,470 --> 00:03:06,950
and I'm calling it, of course, tours.
61
00:03:06,950 --> 00:03:10,530
So create database and here we go.
62
00:03:10,530 --> 00:03:14,880
So open that up, and now open the tours collection.
63
00:03:14,880 --> 00:03:19,520
And now let's then finally insert our first document.
64
00:03:19,520 --> 00:03:22,543
Okay, so again, name,
65
00:03:23,780 --> 00:03:25,123
The Forest Hiker.
66
00:03:27,320 --> 00:03:29,710
The price, should be 297
67
00:03:31,270 --> 00:03:33,483
and I'm giving it a double number here,
68
00:03:34,530 --> 00:03:35,780
and I also want to create
69
00:03:38,520 --> 00:03:39,353
the rating,
70
00:03:40,310 --> 00:03:43,790
4.7, and also as a double.
71
00:03:43,790 --> 00:03:47,680
So insert, and so just like this we have our first tour
72
00:03:47,680 --> 00:03:50,000
created on our remote database.
73
00:03:50,000 --> 00:03:51,840
Great, that's awesome.
74
00:03:51,840 --> 00:03:53,940
Let's now go back actually to Chrome
75
00:03:55,330 --> 00:03:59,890
and take a look at our cluster here,
76
00:03:59,890 --> 00:04:03,730
so when I open up this cluster by clicking here,
77
00:04:03,730 --> 00:04:06,140
then it's gonna load our collections up here
78
00:04:07,970 --> 00:04:09,640
and so give it a second.
79
00:04:09,640 --> 00:04:13,220
And so now, we actually have our database name,
80
00:04:13,220 --> 00:04:16,170
our collection name, and the tour that we just created
81
00:04:16,170 --> 00:04:18,450
in Compass, and that's awesome.
82
00:04:18,450 --> 00:04:21,850
So it means that our connection is really working.
83
00:04:21,850 --> 00:04:24,400
Now another thing that we can and should do,
84
00:04:24,400 --> 00:04:28,250
is to allow access from everywhere to this cluster.
85
00:04:28,250 --> 00:04:30,810
So remember how right in the beginning of this video
86
00:04:30,810 --> 00:04:33,988
we whitelisted our IP in order to grant access
87
00:04:33,988 --> 00:04:37,400
to our current computer to this cluster.
88
00:04:37,400 --> 00:04:40,290
But if you happen to switch computers during development,
89
00:04:40,290 --> 00:04:43,200
you might need to whitelist the IP of that computer as well,
90
00:04:43,200 --> 00:04:46,060
because otherwise you might not be able to connect.
91
00:04:46,060 --> 00:04:48,900
But since we're not really dealing with sensitive data here
92
00:04:48,900 --> 00:04:51,950
anyway, we can simply whitelist every single IP
93
00:04:51,950 --> 00:04:55,060
in the world and allow access from everywhere.
94
00:04:55,060 --> 00:04:57,840
Now of course, we will always still need our username
95
00:04:57,840 --> 00:05:00,350
and our password, but this way we don't need
96
00:05:00,350 --> 00:05:03,010
to keep adding our computers to whitelist.
97
00:05:03,010 --> 00:05:06,370
We will simply whitelist all IPs that exist.
98
00:05:06,370 --> 00:05:10,720
Okay, so click over here on access,
99
00:05:10,720 --> 00:05:14,410
or actually it's not here, so let's open up
100
00:05:14,410 --> 00:05:18,430
this cluster again, and here I think it's on security
101
00:05:18,430 --> 00:05:20,730
and IP whitelist, and now here
102
00:05:20,730 --> 00:05:24,010
on the right side click on add IP address,
103
00:05:24,010 --> 00:05:26,573
and now I wanna allow access from anywhere.
104
00:05:27,520 --> 00:05:30,460
Confirm, and that's it.
105
00:05:30,460 --> 00:05:32,840
Okay, and now just as a last step,
106
00:05:32,840 --> 00:05:37,080
let's also connect our Mongo shell to this cluster.
107
00:05:37,080 --> 00:05:39,740
So let's go back to clusters here,
108
00:05:39,740 --> 00:05:42,380
open up again the connect assistant
109
00:05:43,333 --> 00:05:45,550
and then connect with Mongo shell.
110
00:05:45,550 --> 00:05:48,210
Now we already have it installed here, and so now
111
00:05:48,210 --> 00:05:51,463
all we need to do is to copy this connection string.
112
00:05:52,390 --> 00:05:55,099
So copied it, open up the terminal,
113
00:05:55,099 --> 00:05:58,463
and here we actually still have the Mongo shell running.
114
00:05:59,530 --> 00:06:01,790
So let's quit that very quick,
115
00:06:01,790 --> 00:06:03,860
because remember this is still connected
116
00:06:03,860 --> 00:06:06,810
to our locally running Mongo server.
117
00:06:06,810 --> 00:06:08,590
But now, we no longer want that,
118
00:06:08,590 --> 00:06:11,930
we want to connect to our hosted database.
119
00:06:11,930 --> 00:06:14,350
And so let's copy our string here,
120
00:06:14,350 --> 00:06:18,690
hit return, and it will now probably ask us for our password
121
00:06:18,690 --> 00:06:22,360
and indeed it does and that is in vs code
122
00:06:22,360 --> 00:06:25,743
which I have just here, so copy it,
123
00:06:27,350 --> 00:06:30,470
back to the terminal, paste it, hit return,
124
00:06:30,470 --> 00:06:32,463
and I think it's doing something here.
125
00:06:34,480 --> 00:06:36,950
And it looks like it worked.
126
00:06:36,950 --> 00:06:41,950
So, dbs remember, just to show all the database,
127
00:06:42,020 --> 00:06:44,403
and indeed here we have, natours.
128
00:06:45,250 --> 00:06:48,110
So great, we are connected.
129
00:06:48,110 --> 00:06:50,300
So let's say, use natours,
130
00:06:51,510 --> 00:06:53,640
and so we switched to db natours
131
00:06:54,880 --> 00:06:59,410
and now db.tours.find
132
00:06:59,410 --> 00:07:00,810
and here we have the documents
133
00:07:00,810 --> 00:07:03,950
that we just created before using Compass.
134
00:07:03,950 --> 00:07:07,760
Perfect, so now everything is really interconnected.
135
00:07:07,760 --> 00:07:11,030
We have the Mongo shell, and we have also Compass both
136
00:07:11,030 --> 00:07:15,060
connected to our remote database hosted on Atlas.
137
00:07:15,060 --> 00:07:17,630
And so like this, we are actually ready to move on
138
00:07:17,630 --> 00:07:20,270
to the next section, connect our database
139
00:07:20,270 --> 00:07:23,000
with our express application and then finally
140
00:07:23,000 --> 00:07:26,190
start working with the database in our application.
141
00:07:26,190 --> 00:07:28,550
So great job making it until this point,
142
00:07:28,550 --> 00:07:29,900
and I hope to see you soon.
11269
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.