From the course: Databases for Node.js Developers

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Optimizing queries with indexes

Optimizing queries with indexes - Node.js Tutorial

From the course: Databases for Node.js Developers

Optimizing queries with indexes

- [Instructor] Indexes are a key concept in any type of database, whether relational or non-relational. They are like the index of a book. If you're looking for something specific, the index helps you find it quickly instead of flipping through every single page. In MongoDB, indexes make your queries faster, especially when working with large data sets. They also let us enforce rules like uniqueness, and optimized filtering for sorting operations. Right now and we see this among the big compass, we already have indexes in place. So when I look now into the items collection, and click on the indexes tab, you see that we have an index, which is unique on this ID field we talked about. This is the document ID that is given to us from MongoDB directly, and we also have a unique index SQ. And if you remember that we defined this in the model. So this unique index ensures that no two items can have the same SQ, and it also makes queries way faster because when I now look for an SQ, and it's…

Contents