MongoDB for Developers with Python Transcripts
Chapter: High-performance MongoDB
Lecture: Concept: Indexes via mongoengine
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Now if we're using MongoEngine, we don't have to go to the shell and manually type all the indexes
0:06
we basically go to each individual top level document so all the things that derive from mongoengine.document
0:12
not the embedded documents, and we go to the meta section and we add an indexes, basically array
0:18
so here we want to have, you can see the blue stuff that's highlighted we want an index on make, we want an index on service history
0:24
and within service history, remember these are service records showing on the bottom we went an index the description and price.
0:31
So for index that we put 'make', that's straightforward and then we have service_history.customer_rating so service history is the field name
0:40
and then customer rating is the field name of service record and for some reason I don't have it blue, it's that last one down there
0:46
but we also want this composite key so service_history.price and service_history.description we want to be able to find where both of those match
0:54
and we're going to do that up by having a more complicated entry in the indexes bit here this is going to be a dictionary where the fields are set
1:01
to be this array of strings and not just the flat string itself. So once we add this, when we run our code,
1:08
it's actually going to first time we work with that document ensure that all the indexes are there,
1:13
and remember that like hung up our application for just a little bit, but the real benefit here is our app is always going to be in sync,
1:22
we don't have to go oh oops, I forgot to add the index, that one particular index to say the staging server,
1:28
or when I push to production are there new indexes, I got to go out on the database, now you don't worry about that, you just push your code,
1:35
restart your web app or whatever kind of app it is, and then as part of interacting with it, it will make sure that those indexes are there.
1:42
If you don't want that pause to be there, just go and create the indexes you know the thing is going to create
1:49
put them on the production server and then push the new version of code and it will just go great, these indexes exist.