SlideShare a Scribd company logo
1 of 17
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

The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query OptimizationMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMydbops
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMongoDB
 
Non relational databases-no sql
Non relational databases-no sqlNon relational databases-no sql
Non relational databases-no sqlRam kumar
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLRamakant Soni
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operationsanujaggarwal49
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to ShardingMongoDB
 
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patternsjoergreichert
 

What's hot (20)

The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
 
Spark SQL
Spark SQLSpark SQL
Spark SQL
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Non relational databases-no sql
Non relational databases-no sqlNon relational databases-no sql
Non relational databases-no sql
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQL
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to Sharding
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patterns
 

Viewers also liked

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 cablingKerry Zhang
 
DWDM Transceiver Tutorial
DWDM Transceiver TutorialDWDM Transceiver Tutorial
DWDM Transceiver TutorialKerry Zhang
 
Fanout technology in 40G data center
Fanout technology in 40G data centerFanout technology in 40G data center
Fanout technology in 40G data centerKerry Zhang
 
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
 
Brandon liaw individual
Brandon liaw individualBrandon liaw individual
Brandon liaw individualbrandonliaw97
 
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 centerKerry Zhang
 
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-app6891brandonliaw97
 
Ici assignemnt 2 project brief
Ici assignemnt 2 project briefIci assignemnt 2 project brief
Ici assignemnt 2 project briefbrandonliaw97
 
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_butDelinda Phillips
 
Kirstenbosch Winter wonderland programme 2016
Kirstenbosch Winter wonderland programme 2016Kirstenbosch Winter wonderland programme 2016
Kirstenbosch Winter wonderland programme 2016Cape Coastal Route
 
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 choiceKerry 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

unit 4,Indexes in database.docx
unit 4,Indexes in database.docxunit 4,Indexes in database.docx
unit 4,Indexes in database.docxRaviRajput416403
 
Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26kreuter
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
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 PerformanceJack
 
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.2Antonios 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 indexesRajesh Kumar
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introductiondinkar thakur
 
Storage dei dati con MongoDB
Storage dei dati con MongoDBStorage dei dati con MongoDB
Storage dei dati con MongoDBAndrea Balducci
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo dbEman Mohamed
 
Indexing and Query Optimizer
Indexing and Query OptimizerIndexing and Query Optimizer
Indexing and Query OptimizerMongoDB
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329Douglas Duncan
 
Top MongoDB interview Questions and Answers
Top MongoDB interview Questions and AnswersTop MongoDB interview Questions and Answers
Top MongoDB interview Questions and Answersjeetendra 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
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongoMichael 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)
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 

Recently uploaded (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 

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