SlideShare a Scribd company logo
Indexing
Content
● History of MongoDB
● Overview
● Data Model Designs
● Indexing
● Q&A
History
2007 2009 2013
Founded by 10gen company -
by Dwight Merriman, Eliot
Horowitz and Kevin Ryan – the
team behind DoubleClick.
Officially
launched
10gen changed company name to
MongoDB, Inc
Overview
● MongoDB stores data in a document model, as compared to storing in rows in SQL.
Overview
● MongoDB stores data records as
BSON documents. BSON is a
binary representation of JSON
documents. BSON contains more
data types than JSON.
Data Model Designs
● Relation 1-1
Data Model Designs
● Relation 1-n
Data Model Designs
● Relation n-n
Indexing
● _id Index
● Single field Index
● Compound Index
● Multikey Index
● Wildcard Index
● Text Index
● Hashed Index
● 2dsphere & 2d Index
_id Index
● Default index in MongoDB, automatically generated when creating a new document.
{
"_id": ObjectId("570c04a4ad233577f97dc459"),
"score": 1034,
"location": { state: "NY", city: "New York" }
}
Single Field Index
{
"_id": ObjectId("570c04a4ad233577f97dc459"),
"score": 1034,
"location": { state: "NY", city: "New York" }
}
db.records.createIndex( { score: 1 } )
db.records.find( { score: 2 } )
db.records.find( { score: { $gt: 10 } } )
Compound Index
{
"_id": ObjectId(...),
"item": "Banana",
"category": ["food", "produce", "grocery"],
"location": "4th Street Store",
"stock": 4,
"type": "cases"
}
db.products.createIndex( { "item": 1, "stock": 1 } )
db.products.find( { item: "Banana" } )
db.products.find( { item: "Banana", stock: { $gt: 5 } } )
Multikey Index
{
_id: 1,
item: "abc",
stock: [
{ size: "S", color: "red", quantity: 25 },
{ size: "S", color: "blue", quantity: 10 },
{ size: "M", color: "blue", quantity: 50 }
]
}
db.inventory.createIndex( { "stock.size": 1, "stock.quantity": 1 } )
db.inventory.find( { "stock.size": "M" } )
db.inventory.find( { "stock.size": "M", "stock.quantity": { $lt: 20 } } )
db.inventory.find( { "stock": {"$elemMatch": {"size": "S", "quantity": { $gt: 20 } } } )
Multikey Index
Wildcard Index
{ "userMetadata" : { "likes" : [ "dogs", "cats" ] } }
{ "userMetadata" : { "dislikes" : "pickles" } }
{ "userMetadata" : { "age" : 45 } }
{ "userMetadata" : "inactive" }
db.userData.createIndex( { "userMetadata.$**" : 1 } )
db.userData.find({ "userMetadata.likes" : "dogs" })
db.userData.find({ "userMetadata.dislikes" : "pickles" })
db.userData.find({ "userMetadata.age" : { $gt : 30 } })
db.userData.find({ "userMetadata" : "inactive" })
Text Index
{
_id: 1,
language: "portuguese",
original: "A sorte protege os audazes.",
translation:
[
{
language: "english",
quote: "Fortune favors the bold."
},
{
language: "spanish",
quote: "La suerte protege a los audaces."
}
]
}
db.quotes.createIndex( { original: "text", "translation.quote": "text" } )
db.quotes.find( { $text: { $search: "bold" } } )
Text Index
Hash Index
db.collection.createIndex( { _id: "hashed" } )
● Hashed indexes maintain entries with hashes of the values of the indexed field.
● Support sharding using hashed shard keys. Hashed based sharding uses a hashed index of
a field as the shard key to partition data across your sharded cluster.
2dsphere & 2d Index
db.places.createIndex( { loc : "2dsphere" } )
db.places.find( { loc : { $geoWithin : { $centerSphere : [ [ -88 , 30 ] , 10 / 3963.2 ] } } } )
db.places.createIndex( { loc : "2d" } )
db.places.find( { loc: { $geoWithin : { $center : [ [-74, 40.74 ] , 10 ] } } } )
● A 2dsphere index supports queries that calculate geometries on an earth-like sphere.
● A 2d index for data stored as points on a two-dimensional plane.
{
loc : { type: "Point", coordinates: [ -73.97, 40.77 ] },
name: "Central Park",
category : "Parks"
}
Q&A

More Related Content

Similar to Sharing about MongoDB Overview and Indexing in MongoDB (20)

PPTX
Indexing Strategies to Help You Scale
MongoDB
 
PPT
Introduction to MongoDB
Ravi Teja
 
PPTX
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan
 
PPT
Mongo db tutorials
Anuj Jain
 
PPTX
Introduction to MongoDB
S.Shayan Daneshvar
 
PPT
Mongo db basics
Dhaval Mistry
 
PDF
Mongo db a deep dive of mongodb indexes
Rajesh Kumar
 
PPT
Fast querying indexing for performance (4)
MongoDB
 
PPTX
MongoDB is a document database. It stores data in a type of JSON format calle...
amintafernandos
 
PDF
MongoDB NoSQL database a deep dive -MyWhitePaper
Rajesh Kumar
 
PDF
Mongo db eveningschemadesign
MongoDB APAC
 
PDF
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
PPTX
MongoDB
Bembeng Arifin
 
PPTX
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
SpringPeople
 
KEY
MongoDB
Steven Francia
 
PDF
Introduction to MongoDB
Mike Dirolf
 
PDF
MongodB Internals
Norberto Leite
 
PPTX
introtomongodb
saikiran
 
PPTX
Mongodb introduction and_internal(simple)
Kai Zhao
 
Indexing Strategies to Help You Scale
MongoDB
 
Introduction to MongoDB
Ravi Teja
 
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan
 
Mongo db tutorials
Anuj Jain
 
Introduction to MongoDB
S.Shayan Daneshvar
 
Mongo db basics
Dhaval Mistry
 
Mongo db a deep dive of mongodb indexes
Rajesh Kumar
 
Fast querying indexing for performance (4)
MongoDB
 
MongoDB is a document database. It stores data in a type of JSON format calle...
amintafernandos
 
MongoDB NoSQL database a deep dive -MyWhitePaper
Rajesh Kumar
 
Mongo db eveningschemadesign
MongoDB APAC
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
SpringPeople
 
Introduction to MongoDB
Mike Dirolf
 
MongodB Internals
Norberto Leite
 
introtomongodb
saikiran
 
Mongodb introduction and_internal(simple)
Kai Zhao
 

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Ad

Sharing about MongoDB Overview and Indexing in MongoDB

  • 2. Content ● History of MongoDB ● Overview ● Data Model Designs ● Indexing ● Q&A
  • 3. History 2007 2009 2013 Founded by 10gen company - by Dwight Merriman, Eliot Horowitz and Kevin Ryan – the team behind DoubleClick. Officially launched 10gen changed company name to MongoDB, Inc
  • 4. Overview ● MongoDB stores data in a document model, as compared to storing in rows in SQL.
  • 5. Overview ● MongoDB stores data records as BSON documents. BSON is a binary representation of JSON documents. BSON contains more data types than JSON.
  • 6. Data Model Designs ● Relation 1-1
  • 7. Data Model Designs ● Relation 1-n
  • 8. Data Model Designs ● Relation n-n
  • 9. Indexing ● _id Index ● Single field Index ● Compound Index ● Multikey Index ● Wildcard Index ● Text Index ● Hashed Index ● 2dsphere & 2d Index
  • 10. _id Index ● Default index in MongoDB, automatically generated when creating a new document. { "_id": ObjectId("570c04a4ad233577f97dc459"), "score": 1034, "location": { state: "NY", city: "New York" } }
  • 11. Single Field Index { "_id": ObjectId("570c04a4ad233577f97dc459"), "score": 1034, "location": { state: "NY", city: "New York" } } db.records.createIndex( { score: 1 } ) db.records.find( { score: 2 } ) db.records.find( { score: { $gt: 10 } } )
  • 12. Compound Index { "_id": ObjectId(...), "item": "Banana", "category": ["food", "produce", "grocery"], "location": "4th Street Store", "stock": 4, "type": "cases" } db.products.createIndex( { "item": 1, "stock": 1 } ) db.products.find( { item: "Banana" } ) db.products.find( { item: "Banana", stock: { $gt: 5 } } )
  • 13. Multikey Index { _id: 1, item: "abc", stock: [ { size: "S", color: "red", quantity: 25 }, { size: "S", color: "blue", quantity: 10 }, { size: "M", color: "blue", quantity: 50 } ] } db.inventory.createIndex( { "stock.size": 1, "stock.quantity": 1 } ) db.inventory.find( { "stock.size": "M" } ) db.inventory.find( { "stock.size": "M", "stock.quantity": { $lt: 20 } } ) db.inventory.find( { "stock": {"$elemMatch": {"size": "S", "quantity": { $gt: 20 } } } )
  • 15. Wildcard Index { "userMetadata" : { "likes" : [ "dogs", "cats" ] } } { "userMetadata" : { "dislikes" : "pickles" } } { "userMetadata" : { "age" : 45 } } { "userMetadata" : "inactive" } db.userData.createIndex( { "userMetadata.$**" : 1 } ) db.userData.find({ "userMetadata.likes" : "dogs" }) db.userData.find({ "userMetadata.dislikes" : "pickles" }) db.userData.find({ "userMetadata.age" : { $gt : 30 } }) db.userData.find({ "userMetadata" : "inactive" })
  • 16. Text Index { _id: 1, language: "portuguese", original: "A sorte protege os audazes.", translation: [ { language: "english", quote: "Fortune favors the bold." }, { language: "spanish", quote: "La suerte protege a los audaces." } ] } db.quotes.createIndex( { original: "text", "translation.quote": "text" } ) db.quotes.find( { $text: { $search: "bold" } } )
  • 18. Hash Index db.collection.createIndex( { _id: "hashed" } ) ● Hashed indexes maintain entries with hashes of the values of the indexed field. ● Support sharding using hashed shard keys. Hashed based sharding uses a hashed index of a field as the shard key to partition data across your sharded cluster.
  • 19. 2dsphere & 2d Index db.places.createIndex( { loc : "2dsphere" } ) db.places.find( { loc : { $geoWithin : { $centerSphere : [ [ -88 , 30 ] , 10 / 3963.2 ] } } } ) db.places.createIndex( { loc : "2d" } ) db.places.find( { loc: { $geoWithin : { $center : [ [-74, 40.74 ] , 10 ] } } } ) ● A 2dsphere index supports queries that calculate geometries on an earth-like sphere. ● A 2d index for data stored as points on a two-dimensional plane. { loc : { type: "Point", coordinates: [ -73.97, 40.77 ] }, name: "Central Park", category : "Parks" }
  • 20. Q&A

Editor's Notes

  • #1: https://www.mongodb.com/docs/manual/ https://www.mongodb.com/blog/post/ebay-building-mission-critical-multi-data-center-applications-with-mongodb
  • #3: Founded in 2007 by 10gen company - by Dwight Merriman, Eliot Horowitz and Kevin Ryan – the team behind DoubleClick. Officially launched in 2009 In 2013, 10gen changed company name to MongoDB, Inc Open-source by language C++
  • #19: db.<collection>.find( { <location field> : { $geoWithin : { $centerSphere : [ [ <x>, <y> ] , <radius> ] } } } ) The following example queries grid coordinates and returns all documents within a 10 mile radius of longitude 88 W and latitude 30 N. The example converts the distance, 10 miles, to radians by dividing by the approximate equatorial radius of the earth, 3963.2 miles: db.places.find( { loc : { $geoWithin : { $centerSphere : [ [ -88 , 30 ] , 10 / 3963.2 ] } } } )