1 00:00:00,210 --> 00:00:06,570 In this lesson we're going to start the process of deploying the task manager application to production. 2 00:00:06,570 --> 00:00:12,120 Now this was originally going to be a single video and I actually filmed it but it got a bit complex 3 00:00:12,150 --> 00:00:13,290 and a bit long. 4 00:00:13,290 --> 00:00:17,370 So I'm redoing it breaking it up into two lessons in this lesson. 5 00:00:17,370 --> 00:00:24,240 The goal is to get a production ready Mongo DB database and then the next lesson will actually set everything 6 00:00:24,240 --> 00:00:29,670 up on Heroku to get our application deployed and working with that new database. 7 00:00:29,730 --> 00:00:35,150 But as mentioned step number one is to get a production ready database in place. 8 00:00:35,160 --> 00:00:40,920 Right now the only database we have is the one running locally on our machine and that's not going to 9 00:00:40,920 --> 00:00:44,380 work for when we deploy our application to Heroku. 10 00:00:44,400 --> 00:00:51,480 We want to use a mongo D.B. hosting service to get a database up and running that our Heroku app can 11 00:00:51,480 --> 00:00:52,400 connect to. 12 00:00:52,410 --> 00:00:58,740 Now there are dozens of different companies and services that offer Mongo D.B. database hosting and 13 00:00:58,740 --> 00:01:00,750 the Mongo DB organization. 14 00:01:00,750 --> 00:01:06,930 They actually have their own solution called Atlas and that's what we're gonna be using for this class. 15 00:01:06,930 --> 00:01:11,640 So let's get started by heading over to the browser and we're going to work through all of this together 16 00:01:11,700 --> 00:01:16,320 because getting it set up for the very first time can be a little tricky and I don't want to leave you 17 00:01:16,320 --> 00:01:18,680 hanging with the setup process. 18 00:01:18,760 --> 00:01:24,330 So over here in the browser WE'RE GONNA GOOGLE Mongo D.B. Atlas. 19 00:01:24,480 --> 00:01:30,270 This is going to bring us to the Mongo D.B. Atlas home page and it should look something like this. 20 00:01:30,270 --> 00:01:31,440 That's Mongo DB. 21 00:01:31,440 --> 00:01:36,030 Dot com buzzwords slash cloud forward slash Atlas. 22 00:01:36,120 --> 00:01:39,610 Now once again there are plenty of different solutions we could have gone with. 23 00:01:39,840 --> 00:01:45,510 I'm using this one because it's created by the Mongo D.B. organization so everything is always nice 24 00:01:45,540 --> 00:01:52,500 and up to date and they have a generous free tier so we can get started for free forever and then upgrade 25 00:01:52,500 --> 00:01:54,020 when we have a lot of users. 26 00:01:54,030 --> 00:02:00,210 And it actually makes sense right here we're gonna go ahead and get started for free by clicking start 27 00:02:00,210 --> 00:02:04,260 for free and that'll bring us down to a sign up form down below. 28 00:02:04,260 --> 00:02:09,120 Now as mentioned the setup process can be a bit tricky so we'll go ahead and work through everything 29 00:02:09,120 --> 00:02:13,020 together starting by just registering for an account right here. 30 00:02:13,050 --> 00:02:15,160 Let's go ahead and get that done. 31 00:02:15,210 --> 00:02:16,260 I'll pick a password 32 00:02:19,320 --> 00:02:24,480 and then we're gonna go ahead and agree to the terms of service and we'll click get started for free. 33 00:02:24,480 --> 00:02:28,230 Now once again no need to provide anything like a credit card to get started. 34 00:02:28,260 --> 00:02:31,380 You can get started just by creating an account. 35 00:02:31,380 --> 00:02:36,210 We can go ahead and close the little welcome screen and actually dive into the configuration. 36 00:02:36,210 --> 00:02:41,850 Now by default all of the options picked are gonna allow us to stay on that free tier although we could 37 00:02:41,850 --> 00:02:45,720 easily customize things to move into a paid plan. 38 00:02:45,720 --> 00:02:51,450 So we want to be a bit careful when navigating this page making sure we always see free down below. 39 00:02:51,660 --> 00:02:57,810 Now you'll notice terminology related to creating a cluster as opposed to creating a database. 40 00:02:57,840 --> 00:03:04,560 A cluster is nothing more than a Mongo DB database with multiple servers which can allow you to have 41 00:03:04,590 --> 00:03:07,950 a nice low latency around the globe. 42 00:03:08,190 --> 00:03:12,240 So if we scroll down we can pick options such as the cloud provider. 43 00:03:12,240 --> 00:03:15,060 We'll stick with a W S down below that. 44 00:03:15,060 --> 00:03:21,450 We have our regions so we can choose our primary region and currently only 4 actually support the free 45 00:03:21,450 --> 00:03:26,190 tier so you can pick the closest free tier region to you. 46 00:03:26,250 --> 00:03:29,050 For me North Virginia is pretty close. 47 00:03:29,130 --> 00:03:34,620 Down below we have more things we can customize about the tier additional settings and the name. 48 00:03:34,620 --> 00:03:37,800 We're gonna leave all of those at their default value. 49 00:03:37,800 --> 00:03:44,280 We are on what's known as the m 0 plan and that is the free database plan which comes with half a gig 50 00:03:44,280 --> 00:03:49,000 of storage which will be plenty for us as we test and build out our app. 51 00:03:49,110 --> 00:03:53,010 Then in the future we could always upgrade as we start to get paid users. 52 00:03:53,520 --> 00:03:56,370 So down here we're going to create this cluster. 53 00:03:56,370 --> 00:04:01,020 Now the actual process of creating the cluster does take some time. 54 00:04:01,050 --> 00:04:06,630 You're gonna be redirected over to your dashboard page where you're hit with a lot of information all 55 00:04:06,630 --> 00:04:12,720 at once they have a little checklist of things you need to do in order to connect to your database for 56 00:04:12,720 --> 00:04:19,080 the very first time we can just go ahead and minimize that for the moment and in the background. 57 00:04:19,110 --> 00:04:22,610 Our sandbox instance are free tier instance. 58 00:04:22,650 --> 00:04:25,160 This is being created as we speak. 59 00:04:25,290 --> 00:04:28,840 Now this can actually take between 7 and 10 minutes. 60 00:04:28,920 --> 00:04:35,340 So what we're going to do is just cut the video I'm going to wait until the cluster is created and this 61 00:04:35,340 --> 00:04:37,620 Connect button is enabled. 62 00:04:37,620 --> 00:04:42,120 Take some time to wait for that and when you're done just come back and click play 63 00:04:45,630 --> 00:04:46,190 all right. 64 00:04:46,200 --> 00:04:46,830 We're back. 65 00:04:46,830 --> 00:04:52,790 So our instance has been created and we now have some graphs to keep track of statistics about the database. 66 00:04:52,800 --> 00:04:58,050 Now currently there are no connections there are no operations and there's no storage. 67 00:04:58,050 --> 00:05:03,660 So these graphs are particularly useful but these will start to change as we actually connect read and 68 00:05:03,660 --> 00:05:05,430 write and store data. 69 00:05:05,430 --> 00:05:11,170 Now on the left hand side in order to get started what we need to do is click this Connect button. 70 00:05:11,190 --> 00:05:16,020 This is going to walk us through a little one time setup for this particular cluster. 71 00:05:16,020 --> 00:05:17,850 So right here we're seeing a warning. 72 00:05:17,940 --> 00:05:23,740 You can not connect yet set up a firewall access and use your security permissions below. 73 00:05:23,760 --> 00:05:25,980 So we just have to work through this page. 74 00:05:25,980 --> 00:05:27,150 It's really short. 75 00:05:27,150 --> 00:05:33,570 Then we'll be ready to actually connect to the database both from a gooey and from Visual Studio code 76 00:05:33,630 --> 00:05:34,850 in our project. 77 00:05:34,860 --> 00:05:40,950 So right here let's go ahead and add a different IP address and we're going to provide the following. 78 00:05:40,980 --> 00:05:46,890 That's zero dot 0 0 0 forward slash 0. 79 00:05:46,890 --> 00:05:49,080 This is going to white list all eyepiece. 80 00:05:49,110 --> 00:05:52,040 That's going to be our IP for your local network. 81 00:05:52,140 --> 00:05:58,410 And that's also going to allow this database to be connected from the Heroku because Heroku is going 82 00:05:58,410 --> 00:06:00,500 to change that IP over time. 83 00:06:00,510 --> 00:06:04,110 And we want to make sure we can always connect when it comes to security. 84 00:06:04,110 --> 00:06:10,320 Don't worry we will have a user name and password as well which we'll be configuring down below. 85 00:06:10,320 --> 00:06:16,080 So with this in place for the IP address we can go ahead and click Add IP address which is going to 86 00:06:16,080 --> 00:06:22,740 add it and we can see we've completed one of those steps over here and the next thing to do is to create 87 00:06:22,740 --> 00:06:24,400 a database user. 88 00:06:24,420 --> 00:06:29,190 This is someone who can connect to the database and we're gonna go ahead and pick something that makes 89 00:06:29,190 --> 00:06:30,410 sense for us. 90 00:06:30,450 --> 00:06:37,470 I'll go ahead and say task app as my user name and then I'll also go ahead and provide a password when 91 00:06:37,470 --> 00:06:38,700 you provide the password. 92 00:06:38,700 --> 00:06:44,320 Take a moment to write it down or remember it as this is going to become important in a couple of seconds. 93 00:06:44,340 --> 00:06:49,890 You can always use the Atlas interface to get the password you set later on but we don't want to have 94 00:06:49,890 --> 00:06:52,640 to go back and forth between all the windows. 95 00:06:52,680 --> 00:06:57,120 So right here we're creating the first user for the database which will have access. 96 00:06:57,270 --> 00:07:03,560 We're going to go ahead and click Create Mongo DB user and that's gonna be it for this page. 97 00:07:03,570 --> 00:07:07,400 The next thing we can do is actually connect to the database. 98 00:07:07,410 --> 00:07:14,820 And right here if we continue on to the next step in our little three step wizard it is choose a connection 99 00:07:14,880 --> 00:07:21,360 method and we have three options available connecting from the terminal connecting from our application 100 00:07:21,600 --> 00:07:29,910 or connecting from what's called Mongo D.B. encompass Mongo DB compass is Mongo D BES official gooey 101 00:07:29,970 --> 00:07:30,690 tool. 102 00:07:30,690 --> 00:07:37,910 So it's similar to robo 3D though it's released and maintained by the Mongo DV organization itself. 103 00:07:37,920 --> 00:07:44,520 Now we're actually going to take a quick moment to switch over to mongo DB compos as robo three ti currently 104 00:07:44,520 --> 00:07:51,270 cannot connect to mongo D.B. Atlas databases which is obviously a problem for us. 105 00:07:51,270 --> 00:07:56,670 Hopefully they address that in the future but for the moment we'll just switch to this other gooey. 106 00:07:56,670 --> 00:08:03,060 It's also free available for all operating systems and we can get started right away just as easily 107 00:08:03,060 --> 00:08:09,060 as we were able to with robo 380 and they do the exact same thing and allows us to see and manage our 108 00:08:09,060 --> 00:08:09,750 data. 109 00:08:09,990 --> 00:08:15,690 Right here I'm going to go ahead and grab the download for my operating system that's going to start 110 00:08:15,690 --> 00:08:21,450 the installation process well more like the download process and once it's downloaded we're gonna take 111 00:08:21,450 --> 00:08:28,710 a quick moment to set it up connecting to those two databases one to our local host database and then 112 00:08:28,760 --> 00:08:32,940 two to our Mongo D.B. Atlas database. 113 00:08:32,940 --> 00:08:37,420 Now down below it's showing us to the connection string options we have available. 114 00:08:37,500 --> 00:08:42,800 We are going to go ahead and use this first one that is compass one point 1 2 or later. 115 00:08:43,110 --> 00:08:47,740 And down below we have the connection string which we will eventually copy to the clipboard. 116 00:08:47,880 --> 00:08:54,390 But before we get ahead of ourselves let's go ahead and just get Mongo DB compass setup now like with 117 00:08:54,390 --> 00:08:59,670 all software programs the installation process will be different depending on what OS you're running 118 00:08:59,670 --> 00:09:00,360 on. 119 00:09:00,360 --> 00:09:07,050 For me on a Mac I just need to take the application and drag it over to the applications directory from 120 00:09:07,050 --> 00:09:07,400 there. 121 00:09:07,410 --> 00:09:13,530 I'm going to open the applications directory and we're actually going to boot the program up so I'll 122 00:09:13,530 --> 00:09:16,570 scroll down to M for Mongo D.B.. 123 00:09:16,680 --> 00:09:19,200 And the program is called Mongo D.B.. 124 00:09:19,200 --> 00:09:24,930 Campus community so the community addition is there free edition and that we'll be able to access right 125 00:09:24,930 --> 00:09:25,550 now. 126 00:09:25,830 --> 00:09:31,080 I'm going to go ahead and crack that open and we'll take a quick moment to connect to our local host 127 00:09:31,110 --> 00:09:32,550 database first. 128 00:09:32,880 --> 00:09:36,640 Right here it's asking me if I do want to run this software from the Internet. 129 00:09:36,660 --> 00:09:38,030 Of course I do. 130 00:09:38,070 --> 00:09:44,550 And then we're gonna be brought to the Mongo D.B. campus community application now right here we have 131 00:09:44,550 --> 00:09:49,000 a quick since agreement to agree to and then will be brought to a quick wizard. 132 00:09:49,000 --> 00:09:53,070 We can close that down as we'll work through the setup process together. 133 00:09:53,080 --> 00:09:56,490 We can choose if we want to send those statistics and crash reports. 134 00:09:56,500 --> 00:09:57,760 I always do. 135 00:09:57,880 --> 00:10:01,480 And now we are at any connection screen now by default. 136 00:10:01,480 --> 00:10:02,850 All of the information here. 137 00:10:02,860 --> 00:10:07,920 All of those default values they're going to allow us to connect to the local host database. 138 00:10:07,930 --> 00:10:15,280 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 139 00:10:15,280 --> 00:10:16,740 of these fields. 140 00:10:16,780 --> 00:10:26,120 All I'm going to do is pick a favorite name for this one and I will choose local host Mongo D.B. database. 141 00:10:26,120 --> 00:10:31,370 I'm going to create that as a favorite so I can easily connect to it from right here and then we'll 142 00:10:31,370 --> 00:10:35,090 go ahead and click connect to connect to our local host database. 143 00:10:35,090 --> 00:10:38,630 Right here we have the task manager API. 144 00:10:38,690 --> 00:10:45,260 We have our tasks and users collections and we could crack those open to see the data exactly like we 145 00:10:45,260 --> 00:10:47,820 would be able to in robo 3 T. 146 00:10:47,840 --> 00:10:49,700 So right here I have the documents. 147 00:10:49,700 --> 00:10:54,450 I can also view them in a table view and once again I can manipulate the data. 148 00:10:54,470 --> 00:10:55,820 Insert new documents. 149 00:10:55,820 --> 00:11:00,820 Search the documents and do anything else I'd want to know that this is working. 150 00:11:00,830 --> 00:11:06,710 Let's go ahead and connect to the production database as well so up above what I'm going to do is go 151 00:11:06,710 --> 00:11:10,870 to connect and then I will disconnect from the local host database. 152 00:11:10,970 --> 00:11:15,860 That brings us back to the connection screen and we're going to go ahead and create a new connection 153 00:11:15,920 --> 00:11:17,750 over here in the sidebar. 154 00:11:17,750 --> 00:11:23,120 Now we do have to fill out all of these details and the information we'll be using is information that's 155 00:11:23,120 --> 00:11:26,790 stored in that connection string over in the browser. 156 00:11:26,810 --> 00:11:29,780 So this contains the data we need. 157 00:11:29,780 --> 00:11:32,080 Now it does not contain the password. 158 00:11:32,120 --> 00:11:34,260 But we can go ahead and get started. 159 00:11:34,280 --> 00:11:37,560 What I'm going to start with is just grabbing this right here. 160 00:11:37,580 --> 00:11:38,570 The host. 161 00:11:38,570 --> 00:11:43,700 That is what's after the at sign all the way up to mongo D.B. dot net. 162 00:11:43,700 --> 00:11:45,470 I'm going to copy that to the clipboard. 163 00:11:45,890 --> 00:11:50,970 I'm gonna head back over to Mongo DB compass and paste it in right up top. 164 00:11:50,980 --> 00:11:55,290 Now when it comes to the port we do want to go ahead and stick with the standard port. 165 00:11:55,340 --> 00:12:01,900 And I do want to enable s r v record which we'll talk about in just a little bit down below for authentication 166 00:12:01,910 --> 00:12:08,210 we do have to authenticate and we'll be using a user name and password combination right here. 167 00:12:08,330 --> 00:12:13,880 We have to provide that user name and password we created in that little setup wizard when we clicked 168 00:12:13,910 --> 00:12:15,520 that connect button. 169 00:12:15,530 --> 00:12:19,970 So for me I had called it task app and then I set up my password. 170 00:12:20,000 --> 00:12:27,660 And this is the one that I told you you need to remember for this step down below that we have our authentication 171 00:12:27,660 --> 00:12:28,250 database. 172 00:12:28,260 --> 00:12:30,280 We're going to leave that as is. 173 00:12:30,330 --> 00:12:37,310 We have other information which we don't need SSL that's already set up correctly for Atlas deployment. 174 00:12:37,330 --> 00:12:39,030 SS H tunnel none. 175 00:12:39,030 --> 00:12:41,580 And then down below that our favorite name. 176 00:12:41,580 --> 00:12:48,510 So for this one I could pick something like a production Mongo D.B. database. 177 00:12:48,510 --> 00:12:50,490 I can create that as a favorite. 178 00:12:50,490 --> 00:12:53,210 And then we can go ahead and connect to that as well. 179 00:12:53,220 --> 00:12:58,020 Now when we connect we're not going to see our data because we haven't created any collections and we 180 00:12:58,020 --> 00:13:05,010 haven't inserted any documents but we will get to that in the next video when we finalize the deployment. 181 00:13:05,010 --> 00:13:10,440 For the moment the goal is to just make sure we can actually connect it to the database from outside 182 00:13:10,530 --> 00:13:11,670 of the Web site. 183 00:13:11,700 --> 00:13:17,510 So whether it's from the composite application or from our project in Visual Studio code. 184 00:13:17,550 --> 00:13:20,670 So here we can see that we were able to connect successfully. 185 00:13:20,700 --> 00:13:27,450 Now there is no task manager api database showing up but that will change when we actually connect and 186 00:13:27,450 --> 00:13:31,470 create the database from our application in the next lesson. 187 00:13:31,980 --> 00:13:38,370 So now we can go ahead and disconnect from this as well and we can use Mongo DB compass in the future 188 00:13:38,400 --> 00:13:42,240 to manage our data either locally or in production. 189 00:13:42,270 --> 00:13:47,260 So over here on the left hand side that means we no longer need robo three TI. 190 00:13:47,280 --> 00:13:50,250 We can go ahead and close that program down. 191 00:13:50,280 --> 00:13:54,630 Now there are two quick things I want to talk about first up S.R. v records. 192 00:13:54,630 --> 00:13:56,730 Those come from the DNS world. 193 00:13:56,730 --> 00:14:03,890 They are not specific to mongo D.B. Mongo D.B. Atlas or compass in any way whatsoever. 194 00:14:03,930 --> 00:14:08,730 That is what maps this right here the host to the correct IP and port. 195 00:14:09,210 --> 00:14:13,570 And down below if you forgot the password you created for your user. 196 00:14:13,710 --> 00:14:17,290 You can use the web interface to actually find it. 197 00:14:17,310 --> 00:14:22,390 So over here we're actually done with this whole little modal showing us how we can connect. 198 00:14:22,530 --> 00:14:26,840 We can close that down and start to manage our data from the interface. 199 00:14:26,970 --> 00:14:32,250 What we're going to do is head over to security and here we have Mongo D.B. users. 200 00:14:32,250 --> 00:14:36,680 This contains that user we created in that little setup modal. 201 00:14:36,720 --> 00:14:39,220 We also have IP whitelist over here. 202 00:14:39,240 --> 00:14:42,630 This is where the IP we set up now lives. 203 00:14:42,630 --> 00:14:49,550 Let's go ahead and go back to Mongo DB users will go to edit we'll go to edit password. 204 00:14:49,590 --> 00:14:54,850 Then you can click Show to view the password that you created for your user. 205 00:14:54,870 --> 00:14:58,240 You can then use that when connecting from Mongo DB compass. 206 00:14:58,260 --> 00:15:01,050 If you forgot what the password was. 207 00:15:01,140 --> 00:15:07,140 So now that we have this in place we have a production ready database and we're able to connect to it 208 00:15:07,320 --> 00:15:10,100 from a gooey tool in the next lesson. 209 00:15:10,110 --> 00:15:13,470 We're going to focus on getting everything set up on Heroku. 210 00:15:13,590 --> 00:15:16,290 We need to create the Heroku application. 211 00:15:16,290 --> 00:15:23,130 We need to figure out how to set up environment variables on Heroku and then we need to deploy our code. 212 00:15:23,130 --> 00:15:24,780 I'm really excited to get to that. 213 00:15:24,810 --> 00:15:28,160 So let's go ahead and jump right in to the next lesson.