SlideShare a Scribd company logo
Tips, Trick and HacksGet’n it done!
Basic ExpectationsNo transactionsFast-N-Loose by default (no safe/w/GLE)Indexing order matters; query optimizer helpsOne write threadOne JS thread (M/R, $where, group)Many query threads (non-js)Memory Mapped Data FilesBSON everywhere
IndexesIndex on A, B, C works for [A], [A,B], [A,B,C]Query Optimizer figures out orderHint when you knowMissing values are indexed as “null” valueJust like real “null” valuesUnique indexes include missing/nullsSort works on last field
Shell: FunctionsLeave off the () to see the function:> db.coll.findfunction (query, fields, limit, skip) {    return new DBQuery(this._mongo, this._db, this, this._fullName, this._massageObject(query), fields, limit, skip); }
ConnectionsOrder of ops is only preserved in the same connection (socket/port)Connection pools are good, but could be a problem (getLastError/ordered ops)Server only executes one (concurrent) operation per connection
getLastError()More like getLastOpStatus()Returns useful data on update/findAndModify/insert/remove ops> db.t.update({x:1}, {$inc:{y:1}}, true, true)> db.getLastErrorObj(){        "err" : null,        "updatedExisting" : false,        "upserted" : ObjectId("4c49f54cab620000000071b7"),        "n" : 1,        "ok" : 1 }
getLastErrorParamsParamsw: number of replicas to write towtimeout: time to wait for acknowledgementsfsync: flush to disk{getlasterror : 1, w : 40, wtimeout: 3000}{ "err" : null, "n" : 0, "wtimeout" : true, "waited" : 3006, "errmsg" : "timed out waiting for slaves", "ok" : 0 }
Shell Command Line--evalit/cursorPrinting values; be carefulPass in a script
Enable ProfilingsetProfilingLevel(lvl, <ms>)0: none1: time-based2: allReading from profile collection>db.system.profile.find()
_id: ObjectId Generated on ClientMost drivers create “_id” field (if not set)No way to get “_id” after insert (from server)Nothing  you can’t do yourselfclass Foo {ObjectId id = new ObjectId()   ….}
mongod.confSpecify a logpath or it goes to /dev/nullQuiet = true/anythingDon’t do Quiet = falseFlag options used no matter what valuesV[v*] = true for verbose logging
Limit/Sort/PaginationSort fields should be the last in the indexLimit helps with in-memory sorts (diff alg.)Skip/Offset still walks through indexPagination is best using last “_id”/sort valueSet batchsize = pagesize (under 4MB)
Bulk Data LoadingInitial loadCreate the index after loadStart with new DB if possibleUpdatesBe careful of excessive indexesSometimes better to drop and recreate indexes
Printing Collection Statsdb.getCollectionNames().forEach(function(x){	print(“Collection: “ + x);printjson(db[x].stats());})
BackupsOnly way to get a consistent stateDon’t use mongoexport (lacks type fidelity)Use mongodump (snap-shotted query)Or fsync+copy1.) fsync + lock2.) backup dbpath files3.) release lock
mongostatWatch % idx missfaults/secflushes/sec
QuestionsYou don’t have to go home, but you can’t…ScottHernandez@gmail.com

More Related Content

What's hot (20)

PDF
10 Key MongoDB Performance Indicators
iammutex
 
PDF
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Masahiro Nagano
 
PPTX
Cassandra 2.2 & 3.0
Victor Coustenoble
 
PDF
Building data flows with Celery and SQLAlchemy
Roger Barnes
 
PPTX
Cassandra Community Webinar: Back to Basics with CQL3
DataStax
 
PDF
Tools for Solving Performance Issues
Odoo
 
PDF
아파트 정보를 이용한 ELK stack 활용 - 오근문
NAVER D2
 
PPTX
MongoDB-SESSION03
Jainul Musani
 
PDF
Apache Cassandra and Go
DataStax Academy
 
PDF
Cassandra 3.0 Awesomeness
Jon Haddad
 
PDF
Benchx: An XQuery benchmarking web application
Andy Bunce
 
PDF
Pycon 2012 Apache Cassandra
jeremiahdjordan
 
PPTX
Administering and Monitoring SolrCloud Clusters
Sematext Group, Inc.
 
PDF
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
DataStax
 
PDF
Squeak DBX
ESUG
 
PDF
Service discovery and configuration provisioning
Source Ministry
 
PDF
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
 
PDF
Cutting Edge Data Processing with PHP & XQuery
William Candillon
 
PPTX
Solr Search Engine: Optimize Is (Not) Bad for You
Sematext Group, Inc.
 
PDF
Cassandra 3.0 - JSON at scale - StampedeCon 2015
StampedeCon
 
10 Key MongoDB Performance Indicators
iammutex
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Masahiro Nagano
 
Cassandra 2.2 & 3.0
Victor Coustenoble
 
Building data flows with Celery and SQLAlchemy
Roger Barnes
 
Cassandra Community Webinar: Back to Basics with CQL3
DataStax
 
Tools for Solving Performance Issues
Odoo
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
NAVER D2
 
MongoDB-SESSION03
Jainul Musani
 
Apache Cassandra and Go
DataStax Academy
 
Cassandra 3.0 Awesomeness
Jon Haddad
 
Benchx: An XQuery benchmarking web application
Andy Bunce
 
Pycon 2012 Apache Cassandra
jeremiahdjordan
 
Administering and Monitoring SolrCloud Clusters
Sematext Group, Inc.
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
DataStax
 
Squeak DBX
ESUG
 
Service discovery and configuration provisioning
Source Ministry
 
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
 
Cutting Edge Data Processing with PHP & XQuery
William Candillon
 
Solr Search Engine: Optimize Is (Not) Bad for You
Sematext Group, Inc.
 
Cassandra 3.0 - JSON at scale - StampedeCon 2015
StampedeCon
 

Similar to MongoDB: tips, trick and hacks (20)

PDF
Mongodb debugging-performance-problems
MongoDB
 
PDF
Mongodb in-anger-boston-rb-2011
bostonrb
 
PDF
MongoDB Performance Debugging
MongoDB
 
PPT
Optimizing MongoDB: Lessons Learned at Localytics
Benjamin Darfler
 
PPTX
Indexing with MongoDB
MongoDB
 
PPTX
MongoDB's index and query optimize
mysqlops
 
PPTX
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
PDF
Mongo nyc nyt + mongodb
Deep Kapadia
 
PPTX
What's new in MongoDB 3.6?
MongoDB
 
PDF
Mongo indexes
Mehmet Çetin
 
PDF
Indexing and Query Performance in MongoDB.pdf
Malak Abu Hammad
 
PDF
MongoDB Tokyo - Monitoring and Queueing
Boxed Ice
 
PPTX
Intro To Mongo Db
chriskite
 
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
PPTX
Mongo db tips and advance features
Sujith Sudhakaran
 
PDF
MongoDB Indexing Constraints and Creative Schemas
MongoDB
 
PPT
Tricks
MongoDB
 
PPTX
Neue Features in MongoDB 3.6
MongoDB
 
PDF
Benchmarking at Parse
Travis Redman
 
PDF
Advanced Benchmarking at Parse
MongoDB
 
Mongodb debugging-performance-problems
MongoDB
 
Mongodb in-anger-boston-rb-2011
bostonrb
 
MongoDB Performance Debugging
MongoDB
 
Optimizing MongoDB: Lessons Learned at Localytics
Benjamin Darfler
 
Indexing with MongoDB
MongoDB
 
MongoDB's index and query optimize
mysqlops
 
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
Mongo nyc nyt + mongodb
Deep Kapadia
 
What's new in MongoDB 3.6?
MongoDB
 
Mongo indexes
Mehmet Çetin
 
Indexing and Query Performance in MongoDB.pdf
Malak Abu Hammad
 
MongoDB Tokyo - Monitoring and Queueing
Boxed Ice
 
Intro To Mongo Db
chriskite
 
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
Mongo db tips and advance features
Sujith Sudhakaran
 
MongoDB Indexing Constraints and Creative Schemas
MongoDB
 
Tricks
MongoDB
 
Neue Features in MongoDB 3.6
MongoDB
 
Benchmarking at Parse
Travis Redman
 
Advanced Benchmarking at Parse
MongoDB
 

More from Scott Hernandez (14)

PPTX
MongoDB 2.8 Replication Internals: Fitting it all together
Scott Hernandez
 
PDF
Advanced Replication Internals
Scott Hernandez
 
PPTX
Realtime Analytics with MongoDB Counters (mongonyc 2012)
Scott Hernandez
 
PDF
MongoDB Operational Best Practices (mongosf2012)
Scott Hernandez
 
PDF
MongoDB Datacenter Awareness (mongosf2012)
Scott Hernandez
 
PPTX
Mongo sf easy java persistence
Scott Hernandez
 
PPTX
MongoDB: Easy Java Persistence with Morphia
Scott Hernandez
 
PPTX
MongoDB: Mastering the shell
Scott Hernandez
 
PPTX
MongoDB: Backup, Restore, and DR
Scott Hernandez
 
PPT
A Brief MongoDB Intro
Scott Hernandez
 
PPTX
What's new in the MongoDB Java Driver (2.5)?
Scott Hernandez
 
PPTX
MongoDB Aug2010 SF Meetup
Scott Hernandez
 
PPTX
Mastering the MongoDB Javascript Shell
Scott Hernandez
 
PPTX
Java Development with MongoDB
Scott Hernandez
 
MongoDB 2.8 Replication Internals: Fitting it all together
Scott Hernandez
 
Advanced Replication Internals
Scott Hernandez
 
Realtime Analytics with MongoDB Counters (mongonyc 2012)
Scott Hernandez
 
MongoDB Operational Best Practices (mongosf2012)
Scott Hernandez
 
MongoDB Datacenter Awareness (mongosf2012)
Scott Hernandez
 
Mongo sf easy java persistence
Scott Hernandez
 
MongoDB: Easy Java Persistence with Morphia
Scott Hernandez
 
MongoDB: Mastering the shell
Scott Hernandez
 
MongoDB: Backup, Restore, and DR
Scott Hernandez
 
A Brief MongoDB Intro
Scott Hernandez
 
What's new in the MongoDB Java Driver (2.5)?
Scott Hernandez
 
MongoDB Aug2010 SF Meetup
Scott Hernandez
 
Mastering the MongoDB Javascript Shell
Scott Hernandez
 
Java Development with MongoDB
Scott Hernandez
 

Recently uploaded (20)

PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 

MongoDB: tips, trick and hacks