MongoDB for Developers with Python Transcripts
Chapter: Working with MongoDB directly from Python: PyMongo
Lecture: Mapping MongoDB's JavaScript API to PyMongo

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Now, when you go to and you look through the documentation so, you will find stuff about updates and inserts,
0:09 and queries and aggregation and so on, and so on; all of these are going to be in the Javascript api,
0:15 notice at the bottom of this web page here, db.collection.insertOne is new in version 3.2, so if you're trying to look up these operations
0:23 you will most likely find them in the Javascript style, and the Javascript api,
0:29 that's how MongoDB talks about it, you'll probably find them on Stack Overflow.
0:32 So, because that's the way the shell works, MongoDB is kind of standardized on here is how we're going to do our documentation in Javscript,
0:40 once again, yet another reason we spent so much time on the Javascript api, even though none of us are necessarily Javascript developers.
0:47 So, here we have the crud operations, now we have the query and projection operators and things like that,
0:53 so if you want to know how to map these over to PyMongo, then there's one page really that you need for most things,
1:01 and that's the collection documentation. So over here at
1:11 you can see right at the top, we've got all of the stuff you can do on the collection itself, so for example, we were passing one and minus one
1:19 as the sorting operators in the shell, here you could say pymongo.ascending, pymongo.descending,
1:23 a little bit more explicit, but this is a really good place to go because you'll find like the insert_one and the find_one and all the various ways
1:31 in which you need to adapt the documentation you find in Javascript over to the PyMongo api, this is probably the biggest bang for the buck right here.
1:39 Okay, so if you want to write an app, PyMongo could totally be your data access layer, it would completely solve the problem, it's really great,
1:48 it's what a lot of applications use to talk to MongoDB from Python. We're going to talk about some additional things going forward
1:54 but one of the bigger decisions you need to make is are you going to use an odm that maps classes to MongoDB,
2:01 with additional features as we'll see in a lot of interesting ways, or are you going to work down at the dictionary level,
2:07 it's very similar to say I'm going to work with say the DB api and sql strings, versus SQLAlchemy or Django orm or something like that, right.
2:16 So, you kind of got the low level way to talk to MongoDB, now, we're going to move on to talk about document design
2:22 and mapping higher level objects like classes with MongoEngine later In the course.

Talk Python's Mastodon Michael Kennedy's Mastodon