1 00:00:00,600 --> 00:00:01,433 Instructor: In the last section, 2 00:00:01,433 --> 00:00:03,450 we created our User Schema, 3 00:00:03,450 --> 00:00:05,160 we created a model out of it 4 00:00:05,160 --> 00:00:06,993 and then we exported that model. 5 00:00:08,370 --> 00:00:10,050 Keep in mind that this is all working 6 00:00:10,050 --> 00:00:12,630 with Mongoose right now, and we haven't touched anything 7 00:00:12,630 --> 00:00:14,880 or even installed MongoDB, 8 00:00:14,880 --> 00:00:17,790 which means we don't really have any database yet whatsoever 9 00:00:17,790 --> 00:00:19,800 even though we've got our Schema right here. 10 00:00:19,800 --> 00:00:21,660 So let's spend some time in this section 11 00:00:21,660 --> 00:00:24,813 to actually wire up MongoDB and get it installed. 12 00:00:25,920 --> 00:00:29,460 Installing MongoDB is largely platform specific, 13 00:00:29,460 --> 00:00:30,930 so I am running OSX. 14 00:00:30,930 --> 00:00:33,870 Of course, if you're running Windows or Linux, 15 00:00:33,870 --> 00:00:35,970 the installation is gonna be just a little bit different, 16 00:00:35,970 --> 00:00:38,220 but let's walk through the process a little bit 17 00:00:38,220 --> 00:00:41,400 and I'll tell you where you should be branching off. 18 00:00:41,400 --> 00:00:42,540 I'm gonna open up my browser 19 00:00:42,540 --> 00:00:45,420 to pull up some installation directions. 20 00:00:45,420 --> 00:00:48,513 In a new tab, I'll just search for MongoDB, 21 00:00:50,640 --> 00:00:55,113 the first result is gonna be mongodb.org, go there, 22 00:00:56,250 --> 00:00:59,530 and at the top of the page, find the DOCs section 23 00:01:03,900 --> 00:01:06,810 and then we're almost there, on the left-hand side, 24 00:01:06,810 --> 00:01:10,470 find Installation, so we'll go to Installation 25 00:01:10,470 --> 00:01:12,600 and then we'll scroll down just a little bit, 26 00:01:12,600 --> 00:01:13,890 little bit more, a little bit more, 27 00:01:13,890 --> 00:01:17,190 a little bit more until we find Tutorials. 28 00:01:17,190 --> 00:01:21,750 So these are nice walkthroughs on how to install MongoDB 29 00:01:21,750 --> 00:01:23,250 given a specific platform. 30 00:01:23,250 --> 00:01:25,920 So at this point in time, if you're running Linux 31 00:01:25,920 --> 00:01:27,240 or you're running Windows, 32 00:01:27,240 --> 00:01:30,480 feel free to follow these other sets of instructions 33 00:01:30,480 --> 00:01:32,430 and catch me in the next section, okay? 34 00:01:32,430 --> 00:01:35,910 So basically pause the video, now do installation 35 00:01:35,910 --> 00:01:37,980 and then just go to the next section. 36 00:01:37,980 --> 00:01:40,080 If you have any difficulty with installation 37 00:01:40,080 --> 00:01:43,170 I highly recommend first, if you're getting an error message 38 00:01:43,170 --> 00:01:45,300 just go ahead and do a little bit of googling 39 00:01:45,300 --> 00:01:46,620 on the error message. 40 00:01:46,620 --> 00:01:49,230 If you still can't solve it, feel free to drop me an email 41 00:01:49,230 --> 00:01:51,510 and we'll try to work through it. 42 00:01:51,510 --> 00:01:53,730 So at this point in time, I'm gonna continue forward 43 00:01:53,730 --> 00:01:57,360 with the directions for installing on OSX. 44 00:01:57,360 --> 00:01:58,960 So I'm gonna click on this link, 45 00:02:00,330 --> 00:02:01,920 we'll scroll down a little bit, 46 00:02:01,920 --> 00:02:04,560 scroll down, scroll down, scroll down 47 00:02:04,560 --> 00:02:07,230 and here we go. 48 00:02:07,230 --> 00:02:08,550 So we have step number one, 49 00:02:08,550 --> 00:02:12,450 which is to update Homebrew's Package database. 50 00:02:12,450 --> 00:02:15,330 So Homebrew is a package manager that gets included 51 00:02:15,330 --> 00:02:17,760 with OSX by default. 52 00:02:17,760 --> 00:02:21,600 Over in my command line, I've already ran brew update, 53 00:02:21,600 --> 00:02:22,433 so I'm not... 54 00:02:22,433 --> 00:02:23,490 It takes a little bit to get through, 55 00:02:23,490 --> 00:02:24,930 so I just did it ahead of time, 56 00:02:24,930 --> 00:02:27,730 but I highly recommend you run brew update at this time. 57 00:02:28,890 --> 00:02:30,780 Once brew update has ran successfully, 58 00:02:30,780 --> 00:02:35,780 we'll go onto the next step, which is brew install mongodb. 59 00:02:35,910 --> 00:02:40,563 So I'll do brew install mongodb. 60 00:02:43,590 --> 00:02:46,620 Now I've already downloaded the package ahead of time, 61 00:02:46,620 --> 00:02:48,843 so it almost instantly installs. 62 00:02:53,070 --> 00:02:57,090 Next, we need to do a little bit of setup from MongoDB. 63 00:02:57,090 --> 00:02:58,410 I'm gonna keep scrolling down, 64 00:02:58,410 --> 00:03:01,770 we're gonna pass the Install Community Edition Manually. 65 00:03:01,770 --> 00:03:03,990 Keep going, keep going, 66 00:03:03,990 --> 00:03:07,770 keep going, keep going until you find, Run MongoDB. 67 00:03:07,770 --> 00:03:09,300 So the first thing we need to do here, 68 00:03:09,300 --> 00:03:11,640 is create the data directory. 69 00:03:11,640 --> 00:03:14,738 So by default, Mongo needs a place to actually save the data 70 00:03:14,738 --> 00:03:16,350 that it collects 71 00:03:16,350 --> 00:03:21,000 and by default it does so in this data/db directory. 72 00:03:21,000 --> 00:03:23,520 So this directory does not exist by default 73 00:03:23,520 --> 00:03:25,530 and Mongo will not create it for us, 74 00:03:25,530 --> 00:03:27,180 so we need to actually create it. 75 00:03:30,750 --> 00:03:33,180 Inside of my command line, 76 00:03:33,180 --> 00:03:36,390 we will do just like the line says, 77 00:03:36,390 --> 00:03:41,390 mkdir-p-data or /data/db. 78 00:03:43,500 --> 00:03:45,540 And if you get an error there, no problem, 79 00:03:45,540 --> 00:03:47,580 you might have gotten something that says like, 80 00:03:47,580 --> 00:03:49,500 permission denied, blah, blah, blah. 81 00:03:49,500 --> 00:03:54,500 You can just run sudo mkdir-p /data/db like so. 82 00:03:58,140 --> 00:04:03,140 Once that's done, we need to actually go ahead 83 00:04:03,150 --> 00:04:05,280 and set some permissions on this directory. 84 00:04:05,280 --> 00:04:06,780 So unfortunately this part 85 00:04:06,780 --> 00:04:08,348 is where it gets a little bit messy. 86 00:04:08,348 --> 00:04:09,450 (chuckles) 87 00:04:09,450 --> 00:04:12,000 So this directory that we just created 88 00:04:12,000 --> 00:04:14,880 requires special permissions to access. 89 00:04:14,880 --> 00:04:17,160 And so if we go over here, 90 00:04:17,160 --> 00:04:19,470 I don't think this page actually has the directions 91 00:04:19,470 --> 00:04:20,303 that's fine. 92 00:04:22,290 --> 00:04:25,113 To take over control of that directory, 93 00:04:26,850 --> 00:04:28,830 basically, we need to take over ownership of the directory 94 00:04:28,830 --> 00:04:29,970 we just created. 95 00:04:29,970 --> 00:04:31,110 So here's what we're going to do. 96 00:04:31,110 --> 00:04:33,690 We're gonna do a little bit of fancy command line work. 97 00:04:33,690 --> 00:04:36,090 Well, it's not that fancy, but let's just give it a shot. 98 00:04:36,090 --> 00:04:40,137 So I'm gonna write sudo we'll change ownership-R 99 00:04:42,138 --> 00:04:47,138 $USER/data/db, like so. 100 00:04:50,790 --> 00:04:52,590 So basically what this command right here does, 101 00:04:52,590 --> 00:04:56,133 is it just takes ownership of the directory we just created. 102 00:04:57,480 --> 00:04:59,580 I get prompted for my password, no problem, 103 00:04:59,580 --> 00:05:00,873 and boom, there we go. 104 00:05:02,160 --> 00:05:06,060 So now the very last step is to actually start MongoDB up. 105 00:05:06,060 --> 00:05:11,060 To start up MongoDB, we just run Mongod, no b here, just d, 106 00:05:12,720 --> 00:05:14,160 and there we go. 107 00:05:14,160 --> 00:05:19,160 So you should see some messages on here like up at the top, 108 00:05:19,440 --> 00:05:23,730 MongoDB starting, we should see initializing full-time, 109 00:05:23,730 --> 00:05:24,570 blah, blah, blah 110 00:05:24,570 --> 00:05:27,753 and then waiting for connections on port so and so. 111 00:05:30,930 --> 00:05:33,420 One thing to keep in mind is that by default, 112 00:05:33,420 --> 00:05:36,690 if you wanna use Mongo you have to run that Mongo D command. 113 00:05:36,690 --> 00:05:39,213 So let's say I go and restart my laptop now, 114 00:05:40,050 --> 00:05:42,660 this process and this window would end, 115 00:05:42,660 --> 00:05:45,660 which means Mongo would no longer be running. 116 00:05:45,660 --> 00:05:48,240 So every time they wanna make use of Mongo, 117 00:05:48,240 --> 00:05:51,720 I need to run that mongod command. 118 00:05:51,720 --> 00:05:52,620 If you don't like that, 119 00:05:52,620 --> 00:05:55,440 if you want Mongo to just always run in the background 120 00:05:55,440 --> 00:05:58,560 by default, when we did the Homebrew Install, 121 00:05:58,560 --> 00:06:00,820 there was actually some directions right here 122 00:06:02,460 --> 00:06:07,143 on how to get MongoDB started at login. 123 00:06:08,700 --> 00:06:11,220 So again, I like running it myself, 124 00:06:11,220 --> 00:06:13,470 it's totally up to you if you wanna run it at login. 125 00:06:13,470 --> 00:06:14,760 I really like logging it myself 126 00:06:14,760 --> 00:06:16,980 because I can see any error messages that pop up 127 00:06:16,980 --> 00:06:18,120 or anything like that. 128 00:06:18,120 --> 00:06:20,070 I can also see connections 129 00:06:20,070 --> 00:06:22,533 as they're created to the MongoDB instance. 130 00:06:23,580 --> 00:06:25,800 Okay, so this is great, we've got our server running, 131 00:06:25,800 --> 00:06:28,440 let's go ahead and continue in the next section. 132 00:06:28,440 --> 00:06:29,390 I'll see you there.