MongoDB for Developers with Python Transcripts
Chapter: Working with MongoDB directly from Python: PyMongo
Lecture: Mapping MongoDB's JavaScript API to 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
0:04 so, you will find stuff about updates and inserts,
0:08 and queries and aggregation and so on, and so on;
0:11 all of these are going to be in the Javascript api,
0:14 notice at the bottom of this web page here, db.collection.insertOne
0:18 is new in version 3.2, so if you're trying to look up these operations
0:22 you will most likely find them in the Javascript style, and the Javascript api,
0:28 that's how MongoDB talks about it, you'll probably find them on Stack Overflow.
0:31 So, because that's the way the shell works, MongoDB is kind of standardized
0:36 on here is how we're going to do our documentation in Javscript,
0:39 once again, yet another reason we spent so much time on the Javascript api,
0:42 even though none of us are necessarily Javascript developers.
0:46 So, here we have the crud operations, now we have the query
0:48 and projection operators and things like that,
0:52 so if you want to know how to map these over to PyMongo,
0:56 then there's one page really that you need for most things,
1:00 and that's the collection documentation.
1:03 So over here at
1:10 you can see right at the top, we've got all of the stuff you can do
1:13 on the collection itself, so for example, we were passing one and minus one
1:18 as the sorting operators in the shell,
1:20 here you could say pymongo.ascending, pymongo.descending,
1:22 a little bit more explicit, but this is a really good place to go
1:25 because you'll find like the insert_one and the find_one and all the various ways
1:30 in which you need to adapt the documentation you find in Javascript
1:34 over to the PyMongo api, this is probably the biggest bang for the buck right here.
1:38 Okay, so if you want to write an app,
1:41 PyMongo could totally be your data access layer,
1:44 it would completely solve the problem, it's really great,
1:47 it's what a lot of applications use to talk to MongoDB from Python.
1:50 We're going to talk about some additional things going forward
1:53 but one of the bigger decisions you need to make is
1:56 are you going to use an odm that maps classes to MongoDB,
2:00 with additional features as we'll see in a lot of interesting ways,
2:03 or are you going to work down at the dictionary level,
2:06 it's very similar to say I'm going to work with say the DB api and sql strings,
2:10 versus SQLAlchemy or Django orm or something like that, right.
2:15 So, you kind of got the low level way to talk to MongoDB,
2:18 now, we're going to move on to talk about document design
2:21 and mapping higher level objects like classes with MongoEngine later In the course.