1 00:00:00,975 --> 00:00:04,140 -: In the last section, we got MongoDB up and running. 2 00:00:04,140 --> 00:00:06,300 Just to make sure we're on the same page here 3 00:00:06,300 --> 00:00:09,630 in my terminal, I've got MongoDB very clearly running 4 00:00:09,630 --> 00:00:11,910 by executing the command MongoD. 5 00:00:11,910 --> 00:00:12,960 So at this point in time 6 00:00:12,960 --> 00:00:16,320 we wanna make sure that Mongo is running in a separate tab. 7 00:00:16,320 --> 00:00:17,220 I'm gonna flip back over 8 00:00:17,220 --> 00:00:20,910 to the tab that's hosting Node Mon right now 9 00:00:20,910 --> 00:00:23,333 and then I'm just gonna go back to my code editor. 10 00:00:24,570 --> 00:00:25,530 So at this point in time 11 00:00:25,530 --> 00:00:29,280 we've set up Mongoose with the one single model. 12 00:00:29,280 --> 00:00:33,900 We've got Mongoose running, we've got MongoDB running. 13 00:00:33,900 --> 00:00:38,100 There's just maybe one last missing tiny piece in here. 14 00:00:38,100 --> 00:00:41,460 So we have Mongo- Mongoose running on our server, 15 00:00:41,460 --> 00:00:44,520 but we actually have not formed a distinct connection 16 00:00:44,520 --> 00:00:47,340 between Mongoose and the MongoDB server 17 00:00:47,340 --> 00:00:49,260 that we're running host locally. 18 00:00:49,260 --> 00:00:52,080 So by default, Mongoose does not try to reach 19 00:00:52,080 --> 00:00:53,790 out to your local host and connect 20 00:00:53,790 --> 00:00:57,240 to just any old MongoDB server that's sitting there. 21 00:00:57,240 --> 00:00:59,880 We have to specifically tell it, hey, Mongoose 22 00:00:59,880 --> 00:01:03,093 please go connect to this instance of MongoDB. 23 00:01:04,739 --> 00:01:06,960 To do so, we need to write some setup code 24 00:01:06,960 --> 00:01:09,900 inside of our index.js file. 25 00:01:09,900 --> 00:01:14,900 So inside index.js, I'm going to require Mongoose. 26 00:01:18,330 --> 00:01:19,710 And I'm gonna make another new section 27 00:01:19,710 --> 00:01:22,083 in here called DB setup. 28 00:01:23,310 --> 00:01:25,470 And this is where we're going to tell Mongoose, 29 00:01:25,470 --> 00:01:30,300 hey go connect to this very particular instance of MongoDB. 30 00:01:30,300 --> 00:01:34,410 I'm gonna say Mongoose.connect and then we're gonna 31 00:01:34,410 --> 00:01:37,290 essentially pass it a URL of sorts here. 32 00:01:37,290 --> 00:01:42,290 We're gonna say MongoDB colon slash slash local host. 33 00:01:44,670 --> 00:01:49,547 That means on this server, and then colon auth slash auth. 34 00:01:52,980 --> 00:01:55,560 Internally, this creates a new database inside 35 00:01:55,560 --> 00:01:57,630 of MongoDB called auth. 36 00:01:57,630 --> 00:01:59,340 So if you want to call your database something 37 00:01:59,340 --> 00:02:01,530 slightly different, this would be where you'd change it. 38 00:02:01,530 --> 00:02:02,373 Just right here. 39 00:02:03,930 --> 00:02:06,060 I'm gonna save this file 40 00:02:06,060 --> 00:02:11,060 and now I'm going to Node mon just reran. 41 00:02:11,370 --> 00:02:13,980 So Node mon just node mon just restarted. 42 00:02:13,980 --> 00:02:16,800 I'm gonna flip back over to my Mongo process now 43 00:02:16,800 --> 00:02:19,440 and you can see that I've had several connection accepted 44 00:02:19,440 --> 00:02:21,240 from blah, blah, blah. 45 00:02:21,240 --> 00:02:22,620 Let's go ahead and see what happens 46 00:02:22,620 --> 00:02:25,140 if I kill the Node mon instance that's running. 47 00:02:25,140 --> 00:02:27,270 So I'm gonna flip back over to Node mon 48 00:02:27,270 --> 00:02:30,093 and I'm gonna hit Control C just to stop. 49 00:02:31,320 --> 00:02:34,440 Then I'm gonna go back over to Mongo, and sure enough 50 00:02:34,440 --> 00:02:38,040 I get end connection from 12701. 51 00:02:38,040 --> 00:02:41,370 So that is the server that we were just running. 52 00:02:41,370 --> 00:02:43,740 So we had made a connection with Mongoose 53 00:02:43,740 --> 00:02:47,010 and by ending it, we close the connection. 54 00:02:47,010 --> 00:02:49,260 I'm now gonna go back over to the server. 55 00:02:49,260 --> 00:02:51,303 I'm gonna run NPM run Dev again. 56 00:02:53,670 --> 00:02:56,280 Server starts up, I'm gonna go back over 57 00:02:56,280 --> 00:03:00,563 to MongoDB and connection accepted from 12701. 58 00:03:01,560 --> 00:03:03,930 Perfect. So that means that our server, you know 59 00:03:03,930 --> 00:03:06,300 we've got reasonable belief at this point that 60 00:03:06,300 --> 00:03:10,263 our server is making connection with our MongoDB instance. 61 00:03:11,340 --> 00:03:12,390 So this is fantastic. 62 00:03:12,390 --> 00:03:15,300 There is one more little interesting thing that I 63 00:03:15,300 --> 00:03:17,100 wanna show you guys about MongoDB 64 00:03:17,100 --> 00:03:18,240 that we're going to make a lot 65 00:03:18,240 --> 00:03:20,073 of use of in the coming sections. 66 00:03:21,480 --> 00:03:23,430 Right now when we run MongoDB 67 00:03:23,430 --> 00:03:24,780 it's just running the command line, right? 68 00:03:24,780 --> 00:03:26,160 We can't really see any, any 69 00:03:26,160 --> 00:03:27,930 of the data in here or anything like that. 70 00:03:27,930 --> 00:03:30,540 It would be really fantastic for debugging though 71 00:03:30,540 --> 00:03:32,250 if we could kind of reach directly 72 00:03:32,250 --> 00:03:35,400 into the database and see what records we have. 73 00:03:35,400 --> 00:03:39,000 So there's a fantastic tool that we can download 74 00:03:39,000 --> 00:03:40,470 to do this for us. 75 00:03:40,470 --> 00:03:42,540 It's called Robo Mongo. 76 00:03:42,540 --> 00:03:47,073 So in my browser, I'm going to search for Robo Mongo. 77 00:03:49,200 --> 00:03:51,270 And then the first result on here 78 00:03:51,270 --> 00:03:55,770 I'm gonna find robomongo.org. 79 00:03:55,770 --> 00:03:58,833 I'm gonna go this page at the top right, I'll find download. 80 00:04:00,510 --> 00:04:04,020 And now by default, Robo Mongo is going to ask you 81 00:04:04,020 --> 00:04:06,900 to download the latest version right here at the top. 82 00:04:06,900 --> 00:04:08,850 And if you wanna download the latest version 83 00:04:08,850 --> 00:04:11,250 you have to buy it to download it. 84 00:04:11,250 --> 00:04:12,510 But if you don't wanna spend money 85 00:04:12,510 --> 00:04:15,570 and I don't blame you, if you don't, no problem. 86 00:04:15,570 --> 00:04:17,970 You can download older versions of it. 87 00:04:17,970 --> 00:04:20,459 And basically we're talking about just the, you know 88 00:04:20,459 --> 00:04:23,070 most recent version for free. 89 00:04:23,070 --> 00:04:26,040 So only the latest version you have to pay for, 90 00:04:26,040 --> 00:04:27,990 previous versions you can get for free. 91 00:04:28,860 --> 00:04:31,260 So I'm going to download this 92 00:04:31,260 --> 00:04:33,570 and whatever platform you're on, just go ahead 93 00:04:33,570 --> 00:04:35,970 and download and then go ahead and install it. 94 00:04:35,970 --> 00:04:38,520 So at this point, I encourage you to pause the video 95 00:04:38,520 --> 00:04:40,833 and go through the installation process. 96 00:04:47,370 --> 00:04:49,890 Once you've got Robo Mongo working 97 00:04:49,890 --> 00:04:51,840 let's go ahead and start it up. 98 00:04:51,840 --> 00:04:56,280 So I'll run, oops, Robo Mongo to start it. 99 00:04:56,280 --> 00:04:57,600 I've already got an instance running. 100 00:04:57,600 --> 00:05:00,333 Sorry about that. Let's restart. There we go. 101 00:05:02,610 --> 00:05:05,040 So by default, when you first open Robo Mongo 102 00:05:05,040 --> 00:05:07,890 you won't have any connections listed in here 103 00:05:07,890 --> 00:05:09,960 so I'm just gonna remove my connection just 104 00:05:09,960 --> 00:05:11,943 so we look the same. Very good. 105 00:05:13,320 --> 00:05:15,750 Now, the connections that these are references 106 00:05:15,750 --> 00:05:17,880 to a connection is a connection 107 00:05:17,880 --> 00:05:20,790 to an actual MongoDB database. 108 00:05:20,790 --> 00:05:23,343 So I'm going to create a new connection. 109 00:05:24,480 --> 00:05:26,640 The default settings in here are fantastic, 110 00:05:26,640 --> 00:05:29,370 so we don't really have to change these default settings. 111 00:05:29,370 --> 00:05:30,840 I will change the name, however, 112 00:05:30,840 --> 00:05:31,680 I'm just gonna change the name 113 00:05:31,680 --> 00:05:34,710 to local host just to make it clear that, hey 114 00:05:34,710 --> 00:05:36,960 I'm running this on the local host right now. 115 00:05:37,950 --> 00:05:41,460 I'm gonna save this and makes a new record 116 00:05:41,460 --> 00:05:42,860 and then I'll connect to it. 117 00:05:46,710 --> 00:05:50,010 On the left hand side, I've got a database called auth. 118 00:05:50,010 --> 00:05:52,860 I'll expand on that, and then I expand collections. 119 00:05:52,860 --> 00:05:54,120 And you can see I've already got a little bit 120 00:05:54,120 --> 00:05:55,140 of data loaded in here. 121 00:05:55,140 --> 00:05:56,340 That's totally fine. 122 00:05:56,340 --> 00:05:58,620 Chances are you just have an auth 123 00:05:58,620 --> 00:06:00,180 or maybe not even auth at all. 124 00:06:00,180 --> 00:06:03,360 So as long as you can see essentially local hosts 125 00:06:03,360 --> 00:06:06,063 and system over here, you should be good to go. 126 00:06:07,470 --> 00:06:09,240 Now that we've got Robo Mongo set up 127 00:06:09,240 --> 00:06:11,760 let's go onto the next section, create some new data 128 00:06:11,760 --> 00:06:14,670 inside of our database, and then we can verify it inside 129 00:06:14,670 --> 00:06:17,130 of Robo Mongo and just see it in action. 130 00:06:17,130 --> 00:06:18,930 So I'll see you in the next section.