MongoDB with Async Python Transcripts
Chapter: PyPI Beanie
Lecture: Configuring Collections from Beanie

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So our model matches the data really, really well. But we need to actually make a few more changes to model what's happening inside of MongoDB.
0:11 For example, the collection name. We saw over here that the collection name was lowercase packages. What is it going to be right now?
0:18 Upper case P, singular package. We have no indexes and no ability to specify those either. So recall that what we do is on the top level,
0:29 the Beanie.DocumentDerived class, what we do is we're going to add an inner class here. So let's start with this one, a class called Settings.
0:38 This used to be called Collection, and then that was deprecated and renamed to Settings. So if you see it as Collection in older demos or examples,
0:48 that's the same thing, just rename it to the Settings 'cause the old one doesn't work anymore. So the first thing we want to set
0:54 is the name equals Packages like this. We're also going to go in here, I'll go ahead and put a placeholder for it. We're going to do indexes.
1:02 And those are going to go into here. Obviously, this is the most important thing that we're querying about.
1:10 Like you might want to know, give me the release, you know, is there a release 1.0 for this particular package, right?
1:17 Answering those types of questions, really important. Give me all the packages with this author email,
1:23 or what are all the packages maintained by a singular maintainer?
1:26 all of those things are going to need indexes as well as create a date for like show me
1:32 the most recently updated and the latest releases and those kinds of things.
1:37 So that's what this settings class and we're going to do a bunch of things with the indexes here but not yet.
1:42 Let's go over here to the other two and do something similar. This one was called release analytics I believe. Double check. Release analytics. Yes.
1:54 be users. I'm going to shrink that up for now. All right, I guess keep it consistent, shrink up the packages.
2:15 Excellent. Okay, so now we should be able to talk to MongoDB and actually find the right collections,
2:22 ones that are named the way I think they should be, lowercase plural, when we actually talk to our uppercase P type package here in the queries.
2:34 Now I think we're pretty much ready to go in terms of that connection.
2:38 The last thing we're going to need to do in order to use it is go into B and connect Beanie
2:42 over to MongoDB and tell it that it uses these three classes to do that.


Talk Python's Mastodon Michael Kennedy's Mastodon