From the course: Full Stack Web Development with Flask

Installing database systems

- [Instructor] Working with Databases, section four. In this section, we are going to install the Mongo database system, also installing the MongoEngine extension for Flask, then we're going to be setting up a database for our application, and then we'll be connecting to that database and start creating documents and data, and also creating the data model for our application. To install the MongoDB system, so, we need to into the MongoDB.com website to install the MongoDB into your system. After that, then we're going to install the Mongo engine for Flask, and we do that using the pip install. So let's go into the website and install that DB. Actually, before we go there, you want to check your machine to see if you already have MongoDB installed. If you have it already, that's great, you don't have to do this part, you can skip it, but on the Linux or a Mac machine, you can check it just like you would with any other application if you type in mongo - -version, and as you can see, mine is not working because I'm on a PC, and usually on a PC, it's much more difficult because you have to set that executable file to the environment path, which I didn't, I don't have it, so. But if I do, then you would see the version number, and sometimes you can also use the keyword mongod instead for the version. And again, if you're running on Mac or a Linux machine, that should tell you. Okay, so for Windows, you can't do that, since in this situation you can go into the C drive, usually in the C drive under the program files. So if you enter program files and then it should be installed in a folder called MongoDB. So program files, and then here if you see it, then it should be relisted in here. So, as you can see, I do not have it, so let's go over to the website and install MongoDB. Okay, so on the browser, we just type in mongodb. All right, and the one that we want to install is just the community version, so if you go to products, and under software, MongoDB server, click on that, and it should go to the download center and we want the community server, so again, just choose the version that is fit for your machine, and mine is a Windows 64 so I'm choosing the packaged MSI installer or a ZIP, so I'm going to just choose the MSI, click download to install that. Now, once that is downloaded, you can click install, and then it's going to take a little bit while to install, but just going to wait until it's completely installed, and then we'll move on to the next phase. Okay, so I'm going to go click the installer. Okay, so everything looks good here. Click next and just accept the terms, and next again. You can install a custom version if you want, I'm just going to go ahead and install a complete version just to make sure everything's all there. Now, this option here, again, you can choose the network service user, we can choose a local or domain user, so if you do this option, just make sure you provide some information. Domain would be like IP address. I'm just going to run the server wide user, so again, the default would be just as is, inside the program files, MongoDB in the version four, and so on. Next, the Compass, its interesting interface, where you can actually see databases and all the collections in your database, so this is very similar to if you are using your Microsoft SQL server, will be the Microsoft SQL Management Studio. So I'll go ahead and install that and leave that in there, so later on, if you need to see the databases visually, you can run that application. So click next, and go ahead and install. Again, it might take a while depending on your machine, but we're just going to let it run, and then once it's done, we'll move to the next step. Okay, so it's going. Okay, so looks like it's finished installing, and now it's running the MongoDB Compass Community, which is the user interface where we can interact directly with the database. While that's being loading, we're going to wait for a second to see how long it takes to show up. Okay, so again, just read the agreement and agree to that, and then here we are. Just a little tutorial to walk you through the whole process here. You could just go ahead and close that. Okay, and this is just for reporting stuff to help MongoDB team. I'm not going to enable these, just turn these off, and then here we are. So the local host, the port number by default is 27017, so we will leave that as is. If you are using a different port, then you can change that here, but otherwise, it will be the default port. And then I'm going to go ahead. So here you can see they have three databases come by default, the local, config, and the admin, and on the left side as well, you can see them as well. And go in here and you can see the information in there as well, so you can see the actual documenting here. So this is a collection, is really just a database and this is like a table, right. So it'll be your databases, the local, config and admin, and then of course, later on, you can add more databases into this collection here. Okay, so I'm going to close this one out, and let's go into the command prom with down here. Click and close all of these. Okay, so now let's go into Visual Studio Code, and we need to install the MongoDB. Okay, the Mongo engine is a document object mapper, or DOM, sometimes related to the ORIM, for document databases, and it is used primarily for the MongoDB with Python. So let's go into that in here, I'm going to go to the command prompt, control backtick, and if it's still running, just make sure that's turned off, and then make sure you're also in the virtual environment. So let me clear this. Okay, for now, just make sure you go there. And now, to see if you have something in there already, you can always check by going pip list. That should list the data, the things that you have. So you can see there's no MongoDB in here yet, we're going to install that in here. So let's go and then install that engine in here. So it's very simple, just again, pip install. This is the Flask Mongo engine, okay, so you don't want to just install Mongo engine, you want the one that says flask-mongoengine. This one here is kind of unique because it comes with the WTS friendly. That means you have some forms that already can help you when you create the data model, then we create fields, then they can help you to set the string fields, the text fields and building fields for your database systems. So that's very, very helpful. Okay, so that's going to run, and as you can see, very quick, and let's go ahead and clear the screen here, and you can go ahead and check inside your pip list. It should be listed on there now. Here's the pymongo that came with the installation, along with the mongoengine here, as you can see, came together with it. If you scroll up some more, you'll see the flask-mongoengine. Okay, so this is, again, it's a friendly engine that uses the WTF and some of its properties as well. So now we are pretty good to go, and so before we close out this video, I'm going to update our requirements file, just to make sure we have all these in there. As you can see, if you go into the list here, under our requirements, if you can see that, it just lists some of the things that we have used in the past. So we added some more stuff to it. We want to update this list. So, just by going to, in the command line here, typing the word pip freeze, and then the angle bracket, and then requirements, and then txt. So now it's going to update our list with a newly installed list. So, as you can see, all of the things we installed earlier are all added here now. And we want to keep this updated, just in case if we lost some data or some things are corrupted, we want to reinstall that back. And if you want to see what's inside of requirements, of course, you can click here, or on the command part, you can type in, like, pip then just freeze, and that should list what's inside of requirements, text fall as well. Okay, so now that our MongoDB has been installed and the Flask Mongo engine has been installed, in the next video, we'll be setting up a database for our application.

Contents