MongoDB Indexes II

Learn about the inner workings of indexes and how they help improve query performance.

MongoDB Indexes II

Unit Overview

In this unit, you'll dive into the inner workings of indexes and how they improve performance. Next, you'll learn about tools for evaluating the impact of your indexes on query performance. You'll then explore some additional index types that may be useful for your application patterns. Finally, you'll learn how to monitor the performance of your indexes on MongoDB Atlas and self-managed deployments.

Prerequisites

Lessons in This Unit

  • Lesson 1 – How Indexes Work
  • Lesson 2 – Index Usage Details via Explain
  • Lesson 3 – Optimized Compound Indexes
  • Lesson 4 – Wildcard Indexes
  • Lesson 5 – Partial Indexes
  • Lesson 6 – Sparse Indexes
  • Lesson 7 – Clustered Indexes
  • Lesson 8 – Time Series Collections
  • Lesson 9 – How to Monitor Indexes
  • 01.
    Lesson 1: How Indexes Work
    • Learn
    • Practice
  • 02.
    Lesson 2: Index Usage Details via Explain
    • Learn
    • Practice
  • 03.
    Lesson 3: Optimized Compound Indexes
    • Learn
    • Practice
  • 04.
    Lesson 4: Wildcard Indexes
    • Learn
    • Practice
  • 05.
    Lesson 5: Partial Indexes
    • Learn
    • Practice
  • 06.
    Lesson 6: Sparse Indexes
    • Learn
    • Practice
  • 07.
    Lesson 7: Clustered Indexes
    • Learn
    • Practice: Clustered Indexes
  • 08.
    Lesson 8: Time Series Collections
    • Learn
    • Practice
  • 09.
    Lesson 9: How to Monitor Indexes
    • Learn
    • Practice
  • 10.
    Conclusion
    • Learn
John McCambridge | University Curriculum Engineer

John McCambridge | University Curriculum Engineer

John is a Curriculum Engineer on the University team at MongoDB. Before his work as a Curriculum Engineer, he was an instructor and teaching assistant for coding boot camps at UT (Austin), and UCLA. Additionally, he worked as a QA engineer for a startup called Coder and spent five years at Apple Inc. John is a passionate software engineer and educator who enjoys taking complex topics and making them digestible for the community.

Jordan Smith | Education Engineer

Jordan Smith | Education Engineer

Jordan is an Education Engineer primarily working on MongoDB Driver documentation. Prior to joining MongoDB, Jordan held various Software Engineering positions as a full stack developer. He is passionate about leveraging his skills and experience to educate and mentor others. Outside of work he spends most of his time reading, rock climbing and playing music.

Vick Mena | Director, Curriculum

Vick Mena | Director, Curriculum

My name is Vick and I've been in the wild for over 25 years. I grew up at IBM working on the BIOS for the IBM eServer line in Austin, TX before moving to Wall St. I've worked on all phases of software development from low-level to middleware to UI but feel most comfortable in the middle. I also drank the devops kool-aid having moved a product line to AWS while at Dow Jones & Co with the help of an amazing team. I then pivoted into the secure space and worked on software/hardware reverse engineering. I always thought I'd eventually teach and this role lets me leverage all of my experience to lead this motley crew of passionate educators.

Parker Faucher | University Curriculum Engineer

Parker Faucher | University Curriculum Engineer

Parker is a Curriculum Engineer on the Education team at MongoDB. Prior to joining MongoDB, he helped maintain a world class developer bootcamp that was offered in multiple universities. He is a self taught developer who loves being able to give back to the community that has helped him so much.

HH
October 21, 2023 1:09 PM


bb
October 18, 2023 11:51 AM


RR
October 11, 2023 6:26 AM

Good

UM
October 7, 2023 10:13 AM


GF
October 6, 2023 8:55 AM


Welcome! In this unit, we’ll take a deeper look at how indexes work in MongoDB. My name is Jordan, I am an education engineer here at MongoDB, and I will guide you through this unit.

Before we begin, let's recap what indexes are.

An index is a data structure that stores a subset of the data from a collection in a format that makes it easier for the database to efficiently locate and retrieve documents from disk.

Using indexes in MongoDB can optimize query performance by reducing the time it takes the database to apply the query’s filter and sort conditions, which will make your application operations complete faster.

In this unit, we’ll first start off by learning how MongoDB indexes use a B-tree data structure to store and retrieve indexed values.

Next, we’ll use the explain helper method to better understand if and how operations are supported by indexes.

Then, we’ll go through an in depth example of how we can optimize a compound index by leveraging the explain method.

After that, we’ll learn about some more index types, such as wildcard indexes which are special indexes that support queries against unknown or arbitrary fields.

Next, we’ll cover partial indexes which only index documents from a collection that match a filter expression.

We’ll also discuss sparse indexes which only contain entries for documents that have the indexed field.

Finally, we will cover clustered indexes, and see them in action with our Time Series collection.

Once we’re done learning about some of our different index types, we'll cover how to monitor index usage.

Before taking this unit, you should have knowledge of the document model, MongoDB, and a desire to take your database management skills to the next level. We also advise that you have taken our other unit on indexes.

Let's get started!