SlideShare a Scribd company logo
#AYearWithMongoDB
             The Tips
            By: @rizkyabdilah
Email: rizky@abdi.la / rizky@mindtalk.com
What is MongoDB?
Document database
Schema-free
Memory mapped
Ok, the tips..
#1. Avoid RegExp
Example case, Mindtalk username:
Valid regex ([a-zA-Z0-9_.]+)
No!
db.user.ensureIndex({name: 1})
db.user.insert({name: “Danny”})
db.user.find({name: /dAnny/i})
Yes
db.user.ensureIndex({lower_name: 1})
db.user.insert({name: “Danny”,
  lower_name: “danny”})
db.user.find({lower_name:
  “dAnny”.toLowerCase()})
Comparisson
Index not used when query using RegExp
#2. Tokenize field name
Because of schema-free, every document
  have a own schema (field-name or key in
  json)
#2. Tokenize field name
Because of schema-free, every document
  have a own schema (field-name or key in
  json)
All of your key-name go into your
  'valuable' RAM
#2. Tokenize field name
Because of schema-free, every document
  have a own schema (field-name or key in
  json)
All of your key-name go into your
  'valuable' RAM
Imagine if you've very-very long key-
  name, and it repeated in every
  document. No need to explain
Example Case: Ndayak Stream
How we tackle this
Original            Now:
  Implementation:
                    Index size ~ 12GB
> 136 million doc
                    Space size ~ 15GB
Index size > 60GB
                    AvgObjSize 112
Space size > 24GB     bytes
AvgObjSize 210
#3. Use single compound-key index
 Instead of many single-key index
No
db.post.ensureIndex({user_id: 1, timepos:
  -1})
db.post.ensureIndex({channel_id: 1,
  timepos: -1})
Query find
db.post.find({user_id:
  “uid”}).sort({timepos: -1})
db.post.find({channel_id:
  “ch_id”}).sort({timepos: -1})
Yes
db.post.ensureIndex({user_id:1,
  channel_id: 1, timepos: -1})
Query find, it will use the same index
db.post.find({user_id:
  “uid”}).sort({timepos:-1})
db.post.find({channel_id:
  “chid”}).sort({timepos:-1})
Later Discussions
Global write lock (introducing yield on
  MongoDB 2.0)
Normalize 'own schema'
Sharding?
Thank You
       Ps: don't forget to join channel
#EngineerBlog if you interested in advance :)

More Related Content

What's hot

Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
Mehmet Çetin
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Nosh Petigara
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
Jason Terpko
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in Groovy
Ganesh Samarthyam
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
antoinegirbal
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
Metatagg Solutions
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
MongoDB
 
Getting Started With MongoDB
Getting Started With MongoDBGetting Started With MongoDB
Getting Started With MongoDB
Bill Kunneke
 
Back to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica SetsBack to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica Sets
MongoDB
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHP
ichikaway
 
Rethink db with Python
Rethink db with PythonRethink db with Python
Rethink db with Python
Prabhu Raghav
 
Rethinkdb
RethinkdbRethinkdb
Rethinkdb
Abhi Dey
 
Full Text search in Django with Postgres
Full Text search in Django with PostgresFull Text search in Django with Postgres
Full Text search in Django with Postgres
syerram
 
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
Ontico
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
antoinegirbal
 
Indexing In MongoDB
Indexing In MongoDBIndexing In MongoDB
Indexing In MongoDB
Kishor Parkhe
 
Elastic Search
Elastic SearchElastic Search
Elastic Search
NexThoughts Technologies
 
Python and MongoDB
Python and MongoDB Python and MongoDB
Python and MongoDB
Norberto Leite
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
 
Omnibus database machine
Omnibus database machineOmnibus database machine
Omnibus database machine
Aleck Landgraf
 

What's hot (20)

Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in Groovy
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
 
Getting Started With MongoDB
Getting Started With MongoDBGetting Started With MongoDB
Getting Started With MongoDB
 
Back to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica SetsBack to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica Sets
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHP
 
Rethink db with Python
Rethink db with PythonRethink db with Python
Rethink db with Python
 
Rethinkdb
RethinkdbRethinkdb
Rethinkdb
 
Full Text search in Django with Postgres
Full Text search in Django with PostgresFull Text search in Django with Postgres
Full Text search in Django with Postgres
 
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
 
Indexing In MongoDB
Indexing In MongoDBIndexing In MongoDB
Indexing In MongoDB
 
Elastic Search
Elastic SearchElastic Search
Elastic Search
 
Python and MongoDB
Python and MongoDB Python and MongoDB
Python and MongoDB
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
Omnibus database machine
Omnibus database machineOmnibus database machine
Omnibus database machine
 

Similar to A Year With MongoDB: The Tips

MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
TO THE NEW | Technology
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo db
DaeMyung Kang
 
Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27
MongoDB
 
Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)
MongoDB
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
Tse-Ching Ho
 
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
S.Shayan Daneshvar
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analytics
MongoDB
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
MongoDB
 
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
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
 
About elasticsearch
About elasticsearchAbout elasticsearch
About elasticsearch
Minsoo Jun
 
MongoDB
MongoDBMongoDB
MongoDB
kesavan N B
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
DATAVERSITY
 
Einführung in MongoDB
Einführung in MongoDBEinführung in MongoDB
Einführung in MongoDB
NETUserGroupBern
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
MongoDB
 
Mongo db Quick Guide
Mongo db Quick GuideMongo db Quick Guide
Mongo db Quick Guide
Sourabh Sahu
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
MongoDB
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Andrii Lashchenko
 
MongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo Seattle
MongoDB
 

Similar to A Year With MongoDB: The Tips (20)

MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo db
 
Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27Mongoseattle indexing-2010-07-27
Mongoseattle indexing-2010-07-27
 
Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)Indexing and Query Optimizer (Richard Kreuter)
Indexing and Query Optimizer (Richard Kreuter)
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
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
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analytics
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
 
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.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
 
About elasticsearch
About elasticsearchAbout elasticsearch
About elasticsearch
 
MongoDB
MongoDBMongoDB
MongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Einführung in MongoDB
Einführung in MongoDBEinführung in MongoDB
Einführung in MongoDB
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
 
Mongo db Quick Guide
Mongo db Quick GuideMongo db Quick Guide
Mongo db Quick Guide
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
MongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo Seattle
 

Recently uploaded

healthy relationships and building a friendship
healthy relationships and building a friendshiphealthy relationships and building a friendship
healthy relationships and building a friendship
HaydarbekYuldoshev1
 
Aggression - Applied Social Psychology - Psychology SuperNotes
Aggression - Applied Social Psychology - Psychology SuperNotesAggression - Applied Social Psychology - Psychology SuperNotes
Aggression - Applied Social Psychology - Psychology SuperNotes
PsychoTech Services
 
The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...
The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...
The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...
CANSA The Cancer Association of South Africa
 
Assignment 1 (Introductions to Microsoft Power point 2019) kiran.pptx
Assignment 1 (Introductions to Microsoft Power point 2019) kiran.pptxAssignment 1 (Introductions to Microsoft Power point 2019) kiran.pptx
Assignment 1 (Introductions to Microsoft Power point 2019) kiran.pptx
kirannaveed6
 
1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf
1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf
1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf
shahul62
 
The Six Working Genius Short Explanation
The Six Working Genius Short ExplanationThe Six Working Genius Short Explanation
The Six Working Genius Short Explanation
abijabar2
 
7 Habits of Highly Effective People.pptx
7 Habits of Highly Effective People.pptx7 Habits of Highly Effective People.pptx
7 Habits of Highly Effective People.pptx
gpangilinan2017
 
ProSocial Behaviour - Applied Social Psychology - Psychology SuperNotes
ProSocial Behaviour - Applied Social Psychology - Psychology SuperNotesProSocial Behaviour - Applied Social Psychology - Psychology SuperNotes
ProSocial Behaviour - Applied Social Psychology - Psychology SuperNotes
PsychoTech Services
 
Understanding of Self - Applied Social Psychology - Psychology SuperNotes
Understanding of Self - Applied Social Psychology - Psychology SuperNotesUnderstanding of Self - Applied Social Psychology - Psychology SuperNotes
Understanding of Self - Applied Social Psychology - Psychology SuperNotes
PsychoTech Services
 

Recently uploaded (9)

healthy relationships and building a friendship
healthy relationships and building a friendshiphealthy relationships and building a friendship
healthy relationships and building a friendship
 
Aggression - Applied Social Psychology - Psychology SuperNotes
Aggression - Applied Social Psychology - Psychology SuperNotesAggression - Applied Social Psychology - Psychology SuperNotes
Aggression - Applied Social Psychology - Psychology SuperNotes
 
The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...
The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...
The Secret Warrior - Help Share a Parent or Loved Ones’ Cancer Diagnosis with...
 
Assignment 1 (Introductions to Microsoft Power point 2019) kiran.pptx
Assignment 1 (Introductions to Microsoft Power point 2019) kiran.pptxAssignment 1 (Introductions to Microsoft Power point 2019) kiran.pptx
Assignment 1 (Introductions to Microsoft Power point 2019) kiran.pptx
 
1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf
1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf
1-CIE-IGCSE-Additional-Mathematics-Topical-Past-Paper-Functions.pdf
 
The Six Working Genius Short Explanation
The Six Working Genius Short ExplanationThe Six Working Genius Short Explanation
The Six Working Genius Short Explanation
 
7 Habits of Highly Effective People.pptx
7 Habits of Highly Effective People.pptx7 Habits of Highly Effective People.pptx
7 Habits of Highly Effective People.pptx
 
ProSocial Behaviour - Applied Social Psychology - Psychology SuperNotes
ProSocial Behaviour - Applied Social Psychology - Psychology SuperNotesProSocial Behaviour - Applied Social Psychology - Psychology SuperNotes
ProSocial Behaviour - Applied Social Psychology - Psychology SuperNotes
 
Understanding of Self - Applied Social Psychology - Psychology SuperNotes
Understanding of Self - Applied Social Psychology - Psychology SuperNotesUnderstanding of Self - Applied Social Psychology - Psychology SuperNotes
Understanding of Self - Applied Social Psychology - Psychology SuperNotes
 

A Year With MongoDB: The Tips