SlideShare a Scribd company logo
MongoDB
Indexes
●
Query Analyzing
●
Introduction into indexes
●
Indexes In Mongo
●
Managing indexes in MongoDB
●
Using index to sort query results.
●
When should I use indexes.
●
When should we avoid using indexes.
MongoDB Indexes
Creating experimental collection
●
Selecting Database
●
Inserting fake data in our test collection
“product”. 900000 documents.
●
Products are categorized into 10 categories and
the status of each product could be 0 or 1.
_id name category status
1236**** Prod 1 1 0
1237**** Prod 2 5 0
1238**** Prod 3 9 1
1238**** Prod 4 6 0
1239**** Prod 5 5 1
MongoDB Indexes
Query Analyzing
● db.product.find({category : 5});
●
Searching for products in a specific category.
●
Number of scanned documents.
●
Mongo scans all documents in the collection and
match them with the given condition.
MongoDB Indexes
Query Analyzing
●
If we tried to search for a single document
by _Id using “find” function, we would get
significantly different results.
●
In our case right now we are able to get
same performance just in case we search for
an “_id”.
●
What makes this happen is an index on “_id”
attribute.
MongoDB Indexes
Introduction into indexes
●
How does the normal query work? “linear
search”
●
Indexes can be described as the single and
most critical tool to increase the database
performance.
●
What is it?
An index is a data structure that contains a
copy of some data from database.
MongoDB Indexes
Indexes In Mongo
●
Index Types:
1) Default: _id
2) Single: Similar to Default but could be applied on any of
document fields.
3) Compound: Means defining an index on multiple fields.
Ie : employeeId, salary
4) Multikey: This type of index is used to index a field contains an
array.
We can just define one multikey index per document.
5) GeoSpatial: A set of indexes and query mechanisms to handle
geospatial information.
6) Text: This index is used with text supporting search for string
content.
7) Hashed: This index hashes the value of a field.
Doesn't support range-based queries. Doesn't support multi-key
arrays
Supports only equality matches.
Indexes in Mongo are tree data structured.
For More info search for “b-tree”.
●
Index Properties:
1) Unique.
2) TTL: These are special indexes used to
automatically remove documents after a certain
period of time.
MongoDB Indexes
Indexes In Mongo
Single Index:
It can be applied on any field of a collection.
Embedded Fields & Embedded Documents:
●
We can create indexes on fields within embedded documents.
●
We can create indexes on embedded documents.
MongoDB Indexes
Indexes In Mongo
Compound Index:
Where a single index structure references to more than one field “max of 31” in the same collection.
Let's go back to our example:
We have 900000 products.
Single document example.
Continue to the next slide.
MongoDB Indexes
Indexes In Mongo : Compound
Find query scenarios explanation: more about Explain results
Now Let's create a compound index on both category and status fields:
Find query scenarios explanation:
Continue to the next slide.
MongoDB Indexes
Indexes In Mongo
Find query scenarios explanation: more about Explain results
In the previous slide, it seemed like the index doesn't take effect when we filter documents using “status”
filed, Mongo scanned all 900000 documents. This is because indexing in Mongo is tree structured.
Let's try to explain it again:
Tests from previous slide:
MongoDB Indexes
Indexes In Mongo
Conclusions from compound indexes:
●
Sort indexes is supported by compound index as well as in single index.
●
Sort order can matter in determining whether the index can support a sort operation.
●
Compound index supports indexing by prefixes.
MongoDB Indexes
Indexes In Mongo
Multikey Index:
To index an array or subdocument MongoDB creates an index for each element in the array.
Creation to multikey index is similar to other types, MongoDB would automatically create multikey
index if any indexed field is in array.
Index Arrray with Embedded documents
Simple Array indexing:
MongoDB Indexes
GeoSpatial Index
GeoSpatial Index:
MongoDB offers a number of indexes that allows us to handle geospatial data. That geospatial data
is a geographical information that points to a specific location using longitude and latitude or x and
y in the Cartesian coordinates.
There are two surface types:
●
Flat (1): To calculate distances on a Euclidean plane. Use “2d” index. Supports data stored as
two-dimensional plane, legacy coordinate pairs [x, y].
●
Spherical (2): To calculate geometry over an Earth-like sphere. Use “2dsphere” index. Supports
data stored as GeoJSON object and as legacy coordinate pairs
(1)(2)
MongoDB Indexes
GeoSpatial Index
Simple example of 2d index:
Creating a geospatial data for restaurants
A sample of documents generated by
the previous code.
Creating index:
MongoDB Indexes
GeoSpatial Index
Simple example of 2dsphere index:
Creating a geospatial data for restaurants
A sample of documents generated by
the previous code.
Creating index:
Note: 2dshpere supports data stored as GeoJSON Objects.
For more info about GeoJSON : geojson.org , The following website is a tool to show how GeoJson is structured : geojson.io
for (var i = 0; i < 1000; i++) {
var x = (Math.floor(Math.random() * 20) % 2 == 1 ? "" : "-") + (i + Math.floor(Math.random() * 150)) % 99 + '.' + (i + Math.floor(Math.random() * 100000)) % 1000;
var y = (Math.floor(Math.random() * 20) % 2 == 1 ? "" : "-") + (i + Math.floor(Math.random() * 150)) % 99 + '.' + (i + Math.floor(Math.random() * 100000)) % 1000;
db.places.insert({
"loc": {
type: "Point",
coordinates: [+x, +y]
},
name: "Resturant Num. " + i,
status: i % 2
});
}
MongoDB Indexes
GeoSpatial Index
Geospatial query operators: more info
$geoWithin$near
$polygon $geoWithin
$geoIntersects
$near
$nearSphere
$geometry
$minDistance
$maxDistance
$center
$centerSphere
$box
$polygon
$uniqueDocs
MongoDB Indexes

More Related Content

What's hot

Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
neela madheswari
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
Universidade de São Paulo
 
NOSQL vs SQL
NOSQL vs SQLNOSQL vs SQL
NOSQL vs SQL
Mohammed Fazuluddin
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
Habilelabs
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Dineesha Suraweera
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
Lee Theobald
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
Norberto Leite
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
Christiano Anderson
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
Elasticsearch for beginners
Elasticsearch for beginnersElasticsearch for beginners
Elasticsearch for beginners
Neil Baker
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
 
MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals
Antonios Giannopoulos
 
Introducing MongoDB Atlas
Introducing MongoDB AtlasIntroducing MongoDB Atlas
Introducing MongoDB Atlas
MongoDB
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
Jaya Naresh Kovela
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
MongoDB
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL DatabasesDerek Stainer
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
Bishal Khanal
 
What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...
What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...
What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...
Simplilearn
 

What's hot (20)

Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
NOSQL vs SQL
NOSQL vs SQLNOSQL vs SQL
NOSQL vs SQL
 
MongoDB
MongoDBMongoDB
MongoDB
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
Elasticsearch for beginners
Elasticsearch for beginnersElasticsearch for beginners
Elasticsearch for beginners
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals
 
Introducing MongoDB Atlas
Introducing MongoDB AtlasIntroducing MongoDB Atlas
Introducing MongoDB Atlas
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...
What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...
What Is Apache Spark? | Introduction To Apache Spark | Apache Spark Tutorial ...
 

Viewers also liked

Full metal mongo
Full metal mongoFull metal mongo
Full metal mongo
Israel Gutiérrez
 
40 gbase sr4 qsfp+ transceiver interconnection cabling
40 gbase sr4 qsfp+ transceiver interconnection cabling40 gbase sr4 qsfp+ transceiver interconnection cabling
40 gbase sr4 qsfp+ transceiver interconnection cabling
Kerry Zhang
 
DWDM Transceiver Tutorial
DWDM Transceiver TutorialDWDM Transceiver Tutorial
DWDM Transceiver Tutorial
Kerry Zhang
 
Fanout technology in 40G data center
Fanout technology in 40G data centerFanout technology in 40G data center
Fanout technology in 40G data center
Kerry Zhang
 
Game board proposal
Game board proposalGame board proposal
Game board proposal
brandonliaw97
 
Project 3 residential landscape project march 2015 (1)
Project 3 residential landscape project march 2015 (1)Project 3 residential landscape project march 2015 (1)
Project 3 residential landscape project march 2015 (1)
brandonliaw97
 
Infographic
InfographicInfographic
Infographic
brandonliaw97
 
ENBE FINAL BRIEF
ENBE FINAL BRIEFENBE FINAL BRIEF
ENBE FINAL BRIEF
brandonliaw97
 
Brandon liaw individual
Brandon liaw individualBrandon liaw individual
Brandon liaw individual
brandonliaw97
 
Wbmmf – next generation duplex multimode fiber in the data center
Wbmmf – next generation duplex multimode fiber in the data centerWbmmf – next generation duplex multimode fiber in the data center
Wbmmf – next generation duplex multimode fiber in the data center
Kerry Zhang
 
English 1
English 1English 1
English 1
brandonliaw97
 
Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...
Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...
Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...Chelsea Zabala
 
Interiorarchitecture 150816131601-lva1-app6891
Interiorarchitecture 150816131601-lva1-app6891Interiorarchitecture 150816131601-lva1-app6891
Interiorarchitecture 150816131601-lva1-app6891
brandonliaw97
 
Ici assignemnt 2 project brief
Ici assignemnt 2 project briefIci assignemnt 2 project brief
Ici assignemnt 2 project brief
brandonliaw97
 
Opvvv support to_excellent_research_teams_but
Opvvv support to_excellent_research_teams_butOpvvv support to_excellent_research_teams_but
Opvvv support to_excellent_research_teams_but
Delinda Phillips
 
Kirstenbosch Winter wonderland programme 2016
Kirstenbosch Winter wonderland programme 2016Kirstenbosch Winter wonderland programme 2016
Kirstenbosch Winter wonderland programme 2016
Cape Coastal Route
 
INFORMATICA
INFORMATICAINFORMATICA
INFORMATICA
GamerExpert
 
40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice
40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice
40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice
Kerry Zhang
 

Viewers also liked (20)

Full metal mongo
Full metal mongoFull metal mongo
Full metal mongo
 
40 gbase sr4 qsfp+ transceiver interconnection cabling
40 gbase sr4 qsfp+ transceiver interconnection cabling40 gbase sr4 qsfp+ transceiver interconnection cabling
40 gbase sr4 qsfp+ transceiver interconnection cabling
 
DWDM Transceiver Tutorial
DWDM Transceiver TutorialDWDM Transceiver Tutorial
DWDM Transceiver Tutorial
 
Fanout technology in 40G data center
Fanout technology in 40G data centerFanout technology in 40G data center
Fanout technology in 40G data center
 
Game board proposal
Game board proposalGame board proposal
Game board proposal
 
Project 3 residential landscape project march 2015 (1)
Project 3 residential landscape project march 2015 (1)Project 3 residential landscape project march 2015 (1)
Project 3 residential landscape project march 2015 (1)
 
Infographic
InfographicInfographic
Infographic
 
ENBE FINAL BRIEF
ENBE FINAL BRIEFENBE FINAL BRIEF
ENBE FINAL BRIEF
 
vinod saini
vinod sainivinod saini
vinod saini
 
Brandon liaw individual
Brandon liaw individualBrandon liaw individual
Brandon liaw individual
 
Wbmmf – next generation duplex multimode fiber in the data center
Wbmmf – next generation duplex multimode fiber in the data centerWbmmf – next generation duplex multimode fiber in the data center
Wbmmf – next generation duplex multimode fiber in the data center
 
English 1
English 1English 1
English 1
 
Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...
Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...
Chelsea Zabala - An Exploration of the Importance of Leadership Skills on Nur...
 
Interiorarchitecture 150816131601-lva1-app6891
Interiorarchitecture 150816131601-lva1-app6891Interiorarchitecture 150816131601-lva1-app6891
Interiorarchitecture 150816131601-lva1-app6891
 
Idj 1
Idj 1Idj 1
Idj 1
 
Ici assignemnt 2 project brief
Ici assignemnt 2 project briefIci assignemnt 2 project brief
Ici assignemnt 2 project brief
 
Opvvv support to_excellent_research_teams_but
Opvvv support to_excellent_research_teams_butOpvvv support to_excellent_research_teams_but
Opvvv support to_excellent_research_teams_but
 
Kirstenbosch Winter wonderland programme 2016
Kirstenbosch Winter wonderland programme 2016Kirstenbosch Winter wonderland programme 2016
Kirstenbosch Winter wonderland programme 2016
 
INFORMATICA
INFORMATICAINFORMATICA
INFORMATICA
 
40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice
40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice
40 gbase qsfp+ aoc and 40gbase sr4 qsfp+ transceiver, which is your choice
 

Similar to Mongo indexes

Query Optimization in MongoDB
Query Optimization in MongoDBQuery Optimization in MongoDB
Query Optimization in MongoDB
Hamoon Mohammadian Pour
 
unit 4,Indexes in database.docx
unit 4,Indexes in database.docxunit 4,Indexes in database.docx
unit 4,Indexes in database.docx
RaviRajput416403
 
Nosql part 2
Nosql part 2Nosql part 2
Nosql part 2
Ruru Chowdhury
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb Introduction
Raghvendra Parashar
 
Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26
kreuter
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
MongoDB
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
MongoDB
 
Mongodb Performance
Mongodb PerformanceMongodb Performance
Mongodb Performance
Jack
 
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
Antonios Giannopoulos
 
Mongo db a deep dive of mongodb indexes
Mongo db  a deep dive of mongodb indexesMongo db  a deep dive of mongodb indexes
Mongo db a deep dive of mongodb indexes
Rajesh Kumar
 
Mongo db
Mongo dbMongo db
Mongo db
Gyanendra Yadav
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
dinkar thakur
 
Storage dei dati con MongoDB
Storage dei dati con MongoDBStorage dei dati con MongoDB
Storage dei dati con MongoDB
Andrea Balducci
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
Eman Mohamed
 
Indexing and Query Optimizer
Indexing and Query OptimizerIndexing and Query Optimizer
Indexing and Query Optimizer
MongoDB
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
ElieHannouch
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan
 
Top MongoDB interview Questions and Answers
Top MongoDB interview Questions and AnswersTop MongoDB interview Questions and Answers
Top MongoDB interview Questions and Answers
jeetendra mandal
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
MongoDB
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
Mike Bright
 

Similar to Mongo indexes (20)

Query Optimization in MongoDB
Query Optimization in MongoDBQuery Optimization in MongoDB
Query Optimization in MongoDB
 
unit 4,Indexes in database.docx
unit 4,Indexes in database.docxunit 4,Indexes in database.docx
unit 4,Indexes in database.docx
 
Nosql part 2
Nosql part 2Nosql part 2
Nosql part 2
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb Introduction
 
Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
Mongodb Performance
Mongodb PerformanceMongodb Performance
Mongodb Performance
 
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
 
Mongo db a deep dive of mongodb indexes
Mongo db  a deep dive of mongodb indexesMongo db  a deep dive of mongodb indexes
Mongo db a deep dive of mongodb indexes
 
Mongo db
Mongo dbMongo db
Mongo db
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
Storage dei dati con MongoDB
Storage dei dati con MongoDBStorage dei dati con MongoDB
Storage dei dati con MongoDB
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
 
Indexing and Query Optimizer
Indexing and Query OptimizerIndexing and Query Optimizer
Indexing and Query Optimizer
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
 
Top MongoDB interview Questions and Answers
Top MongoDB interview Questions and AnswersTop MongoDB interview Questions and Answers
Top MongoDB interview Questions and Answers
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 

Recently uploaded

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 

Recently uploaded (20)

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 

Mongo indexes

  • 1. MongoDB Indexes ● Query Analyzing ● Introduction into indexes ● Indexes In Mongo ● Managing indexes in MongoDB ● Using index to sort query results. ● When should I use indexes. ● When should we avoid using indexes.
  • 2. MongoDB Indexes Creating experimental collection ● Selecting Database ● Inserting fake data in our test collection “product”. 900000 documents. ● Products are categorized into 10 categories and the status of each product could be 0 or 1.
  • 3. _id name category status 1236**** Prod 1 1 0 1237**** Prod 2 5 0 1238**** Prod 3 9 1 1238**** Prod 4 6 0 1239**** Prod 5 5 1 MongoDB Indexes Query Analyzing ● db.product.find({category : 5}); ● Searching for products in a specific category. ● Number of scanned documents. ● Mongo scans all documents in the collection and match them with the given condition.
  • 4. MongoDB Indexes Query Analyzing ● If we tried to search for a single document by _Id using “find” function, we would get significantly different results. ● In our case right now we are able to get same performance just in case we search for an “_id”. ● What makes this happen is an index on “_id” attribute.
  • 5. MongoDB Indexes Introduction into indexes ● How does the normal query work? “linear search” ● Indexes can be described as the single and most critical tool to increase the database performance. ● What is it? An index is a data structure that contains a copy of some data from database.
  • 6. MongoDB Indexes Indexes In Mongo ● Index Types: 1) Default: _id 2) Single: Similar to Default but could be applied on any of document fields. 3) Compound: Means defining an index on multiple fields. Ie : employeeId, salary 4) Multikey: This type of index is used to index a field contains an array. We can just define one multikey index per document. 5) GeoSpatial: A set of indexes and query mechanisms to handle geospatial information. 6) Text: This index is used with text supporting search for string content. 7) Hashed: This index hashes the value of a field. Doesn't support range-based queries. Doesn't support multi-key arrays Supports only equality matches. Indexes in Mongo are tree data structured. For More info search for “b-tree”. ● Index Properties: 1) Unique. 2) TTL: These are special indexes used to automatically remove documents after a certain period of time.
  • 7. MongoDB Indexes Indexes In Mongo Single Index: It can be applied on any field of a collection. Embedded Fields & Embedded Documents: ● We can create indexes on fields within embedded documents. ● We can create indexes on embedded documents.
  • 8. MongoDB Indexes Indexes In Mongo Compound Index: Where a single index structure references to more than one field “max of 31” in the same collection. Let's go back to our example: We have 900000 products. Single document example. Continue to the next slide.
  • 9. MongoDB Indexes Indexes In Mongo : Compound Find query scenarios explanation: more about Explain results Now Let's create a compound index on both category and status fields: Find query scenarios explanation: Continue to the next slide.
  • 10. MongoDB Indexes Indexes In Mongo Find query scenarios explanation: more about Explain results In the previous slide, it seemed like the index doesn't take effect when we filter documents using “status” filed, Mongo scanned all 900000 documents. This is because indexing in Mongo is tree structured. Let's try to explain it again: Tests from previous slide:
  • 11. MongoDB Indexes Indexes In Mongo Conclusions from compound indexes: ● Sort indexes is supported by compound index as well as in single index. ● Sort order can matter in determining whether the index can support a sort operation. ● Compound index supports indexing by prefixes.
  • 12. MongoDB Indexes Indexes In Mongo Multikey Index: To index an array or subdocument MongoDB creates an index for each element in the array. Creation to multikey index is similar to other types, MongoDB would automatically create multikey index if any indexed field is in array. Index Arrray with Embedded documents Simple Array indexing:
  • 13. MongoDB Indexes GeoSpatial Index GeoSpatial Index: MongoDB offers a number of indexes that allows us to handle geospatial data. That geospatial data is a geographical information that points to a specific location using longitude and latitude or x and y in the Cartesian coordinates. There are two surface types: ● Flat (1): To calculate distances on a Euclidean plane. Use “2d” index. Supports data stored as two-dimensional plane, legacy coordinate pairs [x, y]. ● Spherical (2): To calculate geometry over an Earth-like sphere. Use “2dsphere” index. Supports data stored as GeoJSON object and as legacy coordinate pairs (1)(2)
  • 14. MongoDB Indexes GeoSpatial Index Simple example of 2d index: Creating a geospatial data for restaurants A sample of documents generated by the previous code. Creating index:
  • 15. MongoDB Indexes GeoSpatial Index Simple example of 2dsphere index: Creating a geospatial data for restaurants A sample of documents generated by the previous code. Creating index: Note: 2dshpere supports data stored as GeoJSON Objects. For more info about GeoJSON : geojson.org , The following website is a tool to show how GeoJson is structured : geojson.io for (var i = 0; i < 1000; i++) { var x = (Math.floor(Math.random() * 20) % 2 == 1 ? "" : "-") + (i + Math.floor(Math.random() * 150)) % 99 + '.' + (i + Math.floor(Math.random() * 100000)) % 1000; var y = (Math.floor(Math.random() * 20) % 2 == 1 ? "" : "-") + (i + Math.floor(Math.random() * 150)) % 99 + '.' + (i + Math.floor(Math.random() * 100000)) % 1000; db.places.insert({ "loc": { type: "Point", coordinates: [+x, +y] }, name: "Resturant Num. " + i, status: i % 2 }); }
  • 16. MongoDB Indexes GeoSpatial Index Geospatial query operators: more info $geoWithin$near $polygon $geoWithin $geoIntersects $near $nearSphere $geometry $minDistance $maxDistance $center $centerSphere $box $polygon $uniqueDocs