MongoDB with Async Python Transcripts
Chapter: Performance Tuning
Lecture: Concept: Projections in Beanie
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Just reviewing projections as a concept in Beanie, remember what we do is we create a class. Here we have package top level only view,
0:10
and it does not derive from the document-based class because you can't do additional queries, you can't insert into the database, none of those things.
0:18
Kind of like a view into the data. And so the way we accomplish that is we just derive from a pedantic base model itself.
0:26
We put in the variables or the fields that we're interested in and then don't forget this, if you forget this, you'll come up with
0:32
none for all those values, which is not ideal, that you create that inner settings class
0:37
and you do this projection where you have a dollar and then the MongoDB in the database
0:43
name and then the field name that you want that to map over to. Then to use it, we just
0:49
have our regular query and then on the end here, we just tack on a dot project. So here
0:56
Or if we wanted to find all the most recently updated packages by some count, we're using
1:01
five in our demo, but we just want the summary information, well, it would sure make a lot
1:06
of sense to say, project just that summary information as we saw.