MongoDB Indexes: Deep Dive, Understanding Indexes.

MongoDB Indexes: Deep Dive, Understanding Indexes.

Getting a performance boost with the best usage of indexes, by understanding what’s the data structure, how it works’s/stored, how is it loaded into memory. How Query optimization make’s decision to select indexes.

Getting a performance boost with the best usage of indexes, by understanding what’s the data structure, how it works’s/stored, how is it loaded into memory. How Query optimization make’s decision to select indexes.

_Basic understanding of indexes is required i.e what are indexes, index types, creating them. [https://docs.mongodb.com/manual/indexes/_](https://docs.mongodb.com/manual/indexes/)

  • Data Structure
  • Storage on disk
  • Memory Allocation.

Data Structure

Index on a filed/fields is stored in order that we specify using B-Tree data structure. Stored in ordered Let see what does it mean’s and how it help’s.

  • Index is created on the value of the filed referencing to the actual document stored.

    Image for post

snipped from: MognoDB university

  • Using B-Tree indexes significantly reduces the number of comparison to find the document.

    Image for post

snipped from: MognoDB university

  • Likewise in below picture we can see with index(sky blue line) even adding document still limit the number of document examined in comparison to without index/collscan.

    Image for post

snipped from: MognoDB university

Storage On Disk

Let’s see/visualize how the index are stored on disk. Index stored on disk is managed by the database storage engine itself.

  • Uses prefix Index compression- Repeated prefix value is not written, let us see example to understand what it mean’s.
db.getCollection("movieTicket")
.ensureIndex({"showDate":1, "seatNo":1, "status":1});

How the index ({“showDate”:1, “seatNo”:1, “status”:1}) is stored on disk.

Image for post

showDate_1_seatNo_1_status_1

index mongodb indexing mongo

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Query of MongoDB | MongoDB Command | MongoDB | Asp.Net Core Mvc

LIKE | COMMENT | SHARE | SUBSCRIBEIn this tutorial, I will discuss the basic query or command of MongoDB Database. We will learn how to Create, Delete, and ...

Install MongoDB Database | MongoDB | Asp.Net Core Mvc

LIKE | COMMENT | SHARE | SUBSCRIBEIn this tutorial, I will discuss how to install MongoDB Database.Blog: http://aspdotnetexplorer.blogspot.comLike our page -...

Insert & Save method in MongoDB | Inserting Document | CRUD Operation in MongoDB

LIKE | COMMENT | SHARE | SUBSCRIBEIn this tutorial, I will discuss the basic query or command of MongoDB Database. We will learn how to insert, Delete the d...

Connecting MongoDB hosted in Mongo Atlas with PowerBI (including M0 clusters)

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training

Execute MongoDB Command | Create, Drop and Select Database | MongoDB | Asp.Net Core Mvc

LIKE | COMMENT | SHARE | SUBSCRIBEIn this tutorial, I will discuss the basic query or command of MongoDB Database. We will learn how to Create, Delete, and ...