Indexing Design Fundamentals

Learn how to design efficient indexes to speed up queries, and reduce resource consumption in MongoDB.

Upon completion of the Indexing Design Fundamentals skill and skill check, you will earn a Credly Badge that you are able to share with your network.


  Learning Objectives

Apply Indexing Best Strategies

Apply best practices including identifying the most frequent queries, creating the minimal number of indexes needed to support those frequent queries and understanding how to build efficient compound indexes.

Optimize Indexes for Performance

Be able to apply strategies such as ESR (equality, sort, range) when appropriate and know how to create indexes for a specific strategy.





Measure Index Performance

Use and interpret the outputs of the tooling such as explain() with your queries to determine if queries are using indexes.

Sarah Evans | Senior Curriculum Engineer

Sarah Evans | Senior Curriculum Engineer

Sarah is a Senior Curriculum Engineer on the Curriculum team at MongoDB. Prior to MongoDB, she taught and developed curricula for developer bootcamps. Sarah has a MAT degree from Columbia University Teachers College and studied Software Engineering at Flatiron School in Chicago, IL.

Manuel Fontan Garcia | Senior Technologist, Education

Manuel Fontan Garcia | Senior Technologist, Education

Manuel is a Senior Technologist on the Curriculum team at MongoDB. Previously he was a Senior Technical Services Engineer in the Core team at MongoDB. In between Manuel worked as a database reliability engineer at Slack for a little over 2 years and then for Cognite until he re-joined MongoDB. With over 15 years experience in software development and distributed systems, he is naturally curious and holds a Telecommunications Engineering MSc from Vigo University (Spain) and a Free and Open Source Software MSc from Rey Juan Carlos University (Spain).

Daniel Curran | Senior Software Engineer

Daniel Curran | Senior Software Engineer

Daniel is a Senior Software Engineer at MongoDB. Before joining MongoDB, he worked as an Instructional Designer and Content Developer specialising in technical content for a host of international clients. Daniel's goal is to remove obstacles so learners can feel confident on their journey to become masters of MongoDB.

John McCambridge | Curriculum Engineer

John McCambridge | 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.

Welcome to this course on indexing design fundamentals.

My name is Sarah, and I'm a curriculum engineer at MongoDB.

To understand what an index is, let's start by looking at an analogy.

Imagine you're moving to a new place, and you need to pack up all of your belongings.

You could just throw everything randomly into boxes, which would certainly save some time while you're packing. But once you arrive, it's going to be time consuming to sort through all of those boxes to find what you need, or you could organize your belongings into labeled boxes before you move. It might take a little longer to pack using this approach, but it'll be much easier to find what you need later.

This is exactly what indexes do in MongoDB.

They create an organized structure that allows for quick retrieval of documents when we query a database.

Without an index, we would have to search through every single document in a collection in order to find the data that we need, and that takes time and resources.

While indexes are an essential part of optimizing query performance, they come with a cost.

Just like our packing analogy, they require more work upfront with right operations.

So it's important to understand how they impact your system so that you can weigh the trade offs.

In this skill, we'll start with an introduction to indexes in MongoDB.

We'll discuss what indexes are, how they optimize query performance using b plus tree structures, the types of indexes available, and the important trade offs to consider when implementing an indexing strategy for your database workloads.

To that end, we will use a messaging application for a financial institution as an example to demonstrate how to apply indexing strategies to a real world scenario.

We'll begin by identifying and analyzing key queries for the application messages collection.

Then we'll examine their common patterns and components to determine the minimum number of indexes needed to support critical workloads.

We'll also introduce you to compound indexes, which is the index type that we will focus on in this skill. Next, we will explore how to structure compound indexes by ordering fields according to the equality sort range or ESR guideline to optimize query performance.

We'll apply this principle to our bank messaging application by analyzing how different field arrangements impact efficiency for our specific query patterns.

Next, we'll examine how to optimize index size. We'll start by discussing prefix compression and how to leverage it by strategically ordering equality fields from lowest to highest cardinality.

We'll also discuss implementing partial indexes to reduce storage requirements. Finally, we'll discuss how to create and manage your indexes. Index management in MongoDB involves planning, monitoring, and maintaining indexes as your data and application evolve.

We'll show you some of the tools and methods that you can use to manage your indexes.

Once you're done, you'll have opportunities to practice creating indexes by completing hands on labs that present real world scenarios.

When you're finished, you'll be ready to put your new skills to the test. To earn your badge, simply complete all the related content, and then take the short test at the end. After passing the test, you'll receive an official Qudly badge via the email you provided. Be sure to share your badge on LinkedIn to show off your new skills.

By completing the skill badge, you will have a working understanding of indexes in MongoDB, be familiar with best practices, and be equipped to apply effective indexing strategies to optimize performance for your specific use case. Let's get started.