MongoDB for Developers with Python Transcripts
Chapter: Mapping classes to MongoDB with the ODM MongoEngine
Lecture: Introducing the application skeleton

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Here we are in the github repository for the course,
0:03 now notice I put the PyMongo play around stuff that we did
0:06 into a folder called dir 5 PyMongo,
0:09 now, we're over into our MongoEngine section,
0:12 and there's actually two things here,
0:14 there's a service central starter and then there's a server central;
0:18 so a lot of times people like to follow along with the code examples
0:20 which I totally encourage, and this one is the way,
0:23 it when we saved in the repository exactly the way we're about to get started.
0:27 This one we're going to evolve throughout this demo
0:30 until it becomes sort of the final version,
0:32 so I want to open this in PyCharm, and I want to use a virtual environment to do that,
0:37 so there's a couple of cool tricks I could do to make a life as easy as possible,
0:40 so here I am in that service central place, and if I do an ls
0:47 even pin files you see there's nothing other than
0:49 this sort of starter Python ting we'll talk about in a minute.
0:51 So the first thing I want to do is I want to actually set up a virtual environment
0:55 with Python 3s venv, I'll do a dash copies, and I'm going to call .env,
1:00 and the name .env here is something that PyCharm will look for,
1:03 so if I open this in PyCharm, after doing this
1:06 it will actually automatically use this virtual environment,
1:09 so that's cool, that'll save me a few clicks.
1:12 Let's go over here and throw this in PyCharm,
1:16 now it's going to take it a second, it's sort of looking
1:19 through that virtual directory, let me add the source control.
1:28 So here's a really simple starter application that we're going to talk about
1:31 but first let's make sure that we have PyMongo installed.
1:34 So let's just do a quick list, and notice
1:37 we're already automatically using our virtual environment,
1:41 that's because it's top level the project, and it's named .env
1:45 so PyCharm said cool, we'll use that, I didn't have to do anything
1:48 that's why I did that first thing in the terminal before open in here.
1:50 So notice we have basically nothing,
1:53 probably worthwhile to upgrade setup tools,
1:59 some of the things that depends on C completion sometimes a little nicer,
2:04 if I have that set up, ok so now we can pip install MongoEngine
2:08 and you'll see that also it's going to install PyMongo,
2:11 depends on 2.7.1. or greater, and it's thinking about PyMongo,
2:15 thinking about MongoEngine, and then we'll be done.
2:19 Perfect, it also uses six for Python 2, Python 3 compatibility.
2:24 All right, so now we have our system all set up, we have PyMongo installed
2:29 and here let me just show you this super simple little app,
2:32 there's absolutely no MongoDB stuff going on,
2:34 so we have this main that is going to print this header,
2:37 very cool, you can see we're going to call our app service central
2:41 and it's going to do this user loop, and the user loop just says
2:46 here's some actions that you can do, you can add a car,
2:48 you can list cars and if you look at implementation,
2:52 all of these are entirely empty,
2:54 here is where the MongoDB stuff is going to be happening,
2:56 so let's go and run this, notice there's no run configuration over here
2:59 no green button to run, so I can right click on this and say run
3:03 and it runs and actually let's make this little higher,
3:07 notice that it's running with the Python out of our virtual environment, Python 3,
3:11 okay, and now here are little header and then here's our user loop,
3:15 it says you can add a car, cool to do add a car,
3:17 you can list the cars, you can find a car, you perform service,
3:21 right so we just basically have the structure in place
3:23 and we're going to use this for the rest of this demo,
3:27 and like I said, we're going to be building on this concept of what we create here.