MongoDB for Developers with Python Transcripts
Chapter: High-performance MongoDB
Lecture: Concept: Projections

Login or purchase this course to watch this video and the rest of the course contents.
0:01 One of the last simple tools you have in your tool belt when we're working with MongoEngine or even in PyMongo, just different api
0:09 is this ability to restrict the data returned from the document. In our car object we've got the make, the model, the id, some other things,
0:18 we've got the engine which is a subdocument or an embedded document there and then the biggest thing that contributes to the size
0:26 is actually the service history which might be many service record entries. If really all we care about is the make, the model and the id of a car,
0:35 and we're going to create like a list or something like that, we can use this .only operator here
0:40 and dramatically reduce the amount of data returned from MongoDB so this is an operation that we saw when we first learned about the api
0:47 actually operates at the database level, you're able to restrict the elements returned from the queries so when it gets back to MongoEngine
0:55 basically it looks at what comes back and it says, alright, I need to create some cars and I need to set their make to this, the model to that
1:02 and their id to whatever comes back, and then nothing else is transferred, deserialized, anything.
1:06 So you can, if you don't need them, exclude the heavyweight things like the engine and the service histories for this particular use case.
1:13 So this is kind of like select make, model, id from table such and such in SQL, and it really can improve the performance
1:23 especially when you have either large documents or many documents. So you've seen a lot of different ways to turn the knobs of MongoDB
1:32 to make it faster and to use MongoEngine to control those knobs. Now this applies to a single individual database server
1:39 and if you use this to tune your database, you can actually make the need for having a sharded cluster and all these scaling things possibly go away,
1:49 but even if you do end up with one of these more interesting topologies, all of these techniques still apply and they'll make your cluster go faster,
1:57 they'll make your replicas go faster, all of those things. What you've learned here are really the foundational items of making MognoDB go fast.


Talk Python's Mastodon Michael Kennedy's Mastodon