MongoDB for Developers with Python Transcripts
Chapter: Working with MongoDB directly from Python: PyMongo
Lecture: Introduction to PyMongo

Login or purchase this course to watch this video and the rest of the course contents.
0:01 All right, the moment you've probably been waiting for is finally here, we're going to start moving away from Javascript
0:07 and doing Python for the rest of this course to talk to MongoDB. That doesn't mean we might not use the Javascript API in the shell,
0:13 just a little bit more, but for the most part we're going to focus now on writing applications that talk to and work with MongoDB.
0:20 So we're going to look at in MongoDB's nomenclature something called a driver, so a driver is the underlying library or framework
0:28 that you used to talk between your application and MongoDB. So here we've got our web app and it's going to be using the database MongoDB here.
0:36 A request is going to come in, into our web app and it's going to use a particular package, right,
0:41 this is not built into Python, this is something we have to go out and get. So the package that we're going to work with
0:46 is built and maintained by MongoDB themselves, and is called PyMongo. So this is the core, lowest level access to the database server
0:55 and it does the tone of things for us, in fact if you look at many of the odms the object document mappers
1:01 the equivalent of the NoSql orm, they build upon PyMongo, right so PyMongo is almost always involved when you're talking to MongoDB from Python.
1:10 And it does many things for us, it connects to the database whether it's local, remote, over ssl, with authentication, with certificates,
1:17 all that kind of stuff, it actually manages replica sets so it knows how to find all the different servers participating in a replica
1:25 and do the fail over if one fails, it knows how to go over to the other one, things like that; it also knows how to deal with sharding,
1:33 so maybe you have a cluster of ten MongoDB servers that are all managing part of the data
1:39 and then participate as a group in the queries, PyMongo does that for us, this is generally where you do the crud operations,
1:45 the find, insert, update, delete, and those kinds of things; you do the other admin stuff as well, like drop tables or create indexes and so on,
1:54 and it even does connection pulling, so really this does all the stuff that you need to talk to MongoDB
1:59 and the api is very, very, very similar to what we saw with the Javascript API which is why I didn't skim over it, I wanted to say, okay,
2:07 you really learned the Javascript api, now you basically also know the PyMongo api, findOne with a capital O, no spaces,
2:14 is now find_one, with a lower case o, for example, there's a few variations for like say Pythonic naming but other than that, PyMongo is going to sound
2:23 and feel very, very familiar to you at this point. Like many things from MongoDB, PyMongo is open source
2:30 so you can come over here to, and that is PyMongo. So you'll see that you can go look around,
2:41 you can see it's under active development and things like that, a lot of stars, so this is like I said, the official driver
2:46 but you also have access to the source, right here. So now that we know about PyMongo, I hope you're ready to go write some code.

Talk Python's Mastodon Michael Kennedy's Mastodon