SlideShare a Scribd company logo
Crazy Stuff : Hacks, Internals, and Sneaky Tricks Dwight Merriman 10gen Mongo D.C. Conference
1. nearly ordered keys have nice properties db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : rand() } )
1. nearly ordered keys db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : rand() } )
1. nearly ordered keys db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : new Date() } )
2. use the embedded time in Object IDs > obj = db.mycoll.findOne(); > obj._id.getTimestamp(); > db.mycoll.find().sort({_id:1}); // time order
3. Store UUIDs as BinData rather than as strings > help misc b = new BinData(subtype,base64str)  create a BSON BinData value b.subtype()  the BinData subtype (0..255) b.length()  length of the BinData data in bytes b.hex()  the data as a hex encoded string b.base64()  the data as a base 64 encoded string b.toString() byte type = BINDATA; char my_fieldname[]; unsigned len = 16; // 16 bytes byte subtype = 3; // UUID char data[16]; //  http://bsonspec.org/#/specification
4. Field name lengths
4. Use covered compound indexes to create materialized views* * coming soon! -- your current build may not be fast yet > // { a : ..., b : ..., c : ..., d : ..., e : ..., f : reallybigdata, g : ... } > t.ensureIndex( { b : 1, d : 1, e : 1 } ) > f.find( {}, { b : 1, d : 1, e : 1 } )
5. query the replication oplog
6. making a replay log --diaglog  or db._adminCommand( { diagLogging : 1 } ) Output is written to diaglog.bin_ 0 off. Also flushes any pending data to the file. 1 log writes 2 log reads 3 log both nc ''database_server_ip'' 27017 < ''somelog.bin'' | hexdump -c good for qa? good for bug reports?
7. Manually padding records obj.padding = “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”; coll.insert(obj); coll.update({_id:obj._id}, { $unset : { padding : 1 } });
8. other things you should be using (checklist) multikeys dot notation “ fire and forget” (i.e., don’t call getLastError for noncritical writes) upserts the HTTP admin page for replica sets
thanks questions? [email_address] @dmerr Please follow @mongodb on twitter. Sign up with 10gen for a 1 day “db design sanity check and design tuning” session. Email  [email_address] 10gen is hiring in Bay Area and New York. Up Next 11:00-11:30 MongoDB and the Democratic Party -- A Case Study How Sunlight Labs Uses MongoDB

More Related Content

PDF
Herding types with Scala macros
PDF
What they don't tell you about JavaScript
PDF
Data structure programs in c++
PDF
Redis the better NoSQL
PDF
20110514 mongo dbチューニング
PPTX
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3
PDF
Nosql hands on handout 04
PDF
MySQL flexible schema and JSON for Internet of Things
Herding types with Scala macros
What they don't tell you about JavaScript
Data structure programs in c++
Redis the better NoSQL
20110514 mongo dbチューニング
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3
Nosql hands on handout 04
MySQL flexible schema and JSON for Internet of Things

What's hot (20)

PDF
Cluj Big Data Meetup - Big Data in Practice
PDF
Script for Spatial Mongo
PDF
AJUG April 2011 Raw hadoop example
PDF
Zone.js 2017
PDF
Open XKE - Big Data, Big Mess par Bertrand Dechoux
PPTX
MongoDB - Aggregation Pipeline
PDF
Latinoware
PPTX
Mythbusting: Understanding How We Measure the Performance of MongoDB
PDF
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
PDF
Building apps why you should bet on the web
PPTX
Weather of the Century: Design and Performance
PDF
The Ring programming language version 1.10 book - Part 78 of 212
PDF
The Ring programming language version 1.9 book - Part 78 of 210
PDF
"You shall not pass : anti-debug methodics"
PDF
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PPTX
Mythbusting: Understanding How We Measure Performance at MongoDB
PPTX
Deep dumpster diving 2010
ODP
Mongo db dla administratora
PPTX
Working with NoSQL in a SQL Database (XDevApi)
PPTX
NoSQL in SQL - Lior Altarescu
Cluj Big Data Meetup - Big Data in Practice
Script for Spatial Mongo
AJUG April 2011 Raw hadoop example
Zone.js 2017
Open XKE - Big Data, Big Mess par Bertrand Dechoux
MongoDB - Aggregation Pipeline
Latinoware
Mythbusting: Understanding How We Measure the Performance of MongoDB
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Building apps why you should bet on the web
Weather of the Century: Design and Performance
The Ring programming language version 1.10 book - Part 78 of 212
The Ring programming language version 1.9 book - Part 78 of 210
"You shall not pass : anti-debug methodics"
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
Mythbusting: Understanding How We Measure Performance at MongoDB
Deep dumpster diving 2010
Mongo db dla administratora
Working with NoSQL in a SQL Database (XDevApi)
NoSQL in SQL - Lior Altarescu
Ad

Viewers also liked (6)

PPTX
Why mongo db was created - Dwight Merriman - MongoSF 2011
KEY
2011 mongo sf-scaling
PPTX
Webinar: Utilisations courantes de MongoDB
PPTX
High Performance, Scalable MongoDB in a Bare Metal Cloud
KEY
Scaling with MongoDB
PPTX
MongoDB San Francisco 2013: Storing eBay's Media Metadata on MongoDB present...
Why mongo db was created - Dwight Merriman - MongoSF 2011
2011 mongo sf-scaling
Webinar: Utilisations courantes de MongoDB
High Performance, Scalable MongoDB in a Bare Metal Cloud
Scaling with MongoDB
MongoDB San Francisco 2013: Storing eBay's Media Metadata on MongoDB present...
Ad

Similar to Tricks (20)

PDF
Mongodb in-anger-boston-rb-2011
PDF
Building Apps with MongoDB
PPT
Building Your First MongoDB App ~ Metadata Catalog
KEY
2012 phoenix mug
PDF
FrozenRails Training
PDF
MongoDB Tokyo - Monitoring and Queueing
PPT
Mongo db tutorials
PDF
Quick overview on mongo db
KEY
PPTX
Intro To Mongo Db
PDF
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
PDF
MongoDB for Coder Training (Coding Serbia 2013)
PDF
San Francisco Java User Group
PPT
Optimizing MongoDB: Lessons Learned at Localytics
PDF
MongoDB.pdf
KEY
Seedhack MongoDB 2011
PPT
Introduction to MongoDB
ODP
A Year With MongoDB: The Tips
PDF
Inside MongoDB: the Internals of an Open-Source Database
Mongodb in-anger-boston-rb-2011
Building Apps with MongoDB
Building Your First MongoDB App ~ Metadata Catalog
2012 phoenix mug
FrozenRails Training
MongoDB Tokyo - Monitoring and Queueing
Mongo db tutorials
Quick overview on mongo db
Intro To Mongo Db
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB for Coder Training (Coding Serbia 2013)
San Francisco Java User Group
Optimizing MongoDB: Lessons Learned at Localytics
MongoDB.pdf
Seedhack MongoDB 2011
Introduction to MongoDB
A Year With MongoDB: The Tips
Inside MongoDB: the Internals of an Open-Source Database

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...

Tricks

  • 1. Crazy Stuff : Hacks, Internals, and Sneaky Tricks Dwight Merriman 10gen Mongo D.C. Conference
  • 2. 1. nearly ordered keys have nice properties db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : rand() } )
  • 3. 1. nearly ordered keys db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : rand() } )
  • 4. 1. nearly ordered keys db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : new Date() } )
  • 5. 2. use the embedded time in Object IDs > obj = db.mycoll.findOne(); > obj._id.getTimestamp(); > db.mycoll.find().sort({_id:1}); // time order
  • 6. 3. Store UUIDs as BinData rather than as strings > help misc b = new BinData(subtype,base64str) create a BSON BinData value b.subtype() the BinData subtype (0..255) b.length() length of the BinData data in bytes b.hex() the data as a hex encoded string b.base64() the data as a base 64 encoded string b.toString() byte type = BINDATA; char my_fieldname[]; unsigned len = 16; // 16 bytes byte subtype = 3; // UUID char data[16]; // http://bsonspec.org/#/specification
  • 7. 4. Field name lengths
  • 8. 4. Use covered compound indexes to create materialized views* * coming soon! -- your current build may not be fast yet > // { a : ..., b : ..., c : ..., d : ..., e : ..., f : reallybigdata, g : ... } > t.ensureIndex( { b : 1, d : 1, e : 1 } ) > f.find( {}, { b : 1, d : 1, e : 1 } )
  • 9. 5. query the replication oplog
  • 10. 6. making a replay log --diaglog or db._adminCommand( { diagLogging : 1 } ) Output is written to diaglog.bin_ 0 off. Also flushes any pending data to the file. 1 log writes 2 log reads 3 log both nc ''database_server_ip'' 27017 < ''somelog.bin'' | hexdump -c good for qa? good for bug reports?
  • 11. 7. Manually padding records obj.padding = “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”; coll.insert(obj); coll.update({_id:obj._id}, { $unset : { padding : 1 } });
  • 12. 8. other things you should be using (checklist) multikeys dot notation “ fire and forget” (i.e., don’t call getLastError for noncritical writes) upserts the HTTP admin page for replica sets
  • 13. thanks questions? [email_address] @dmerr Please follow @mongodb on twitter. Sign up with 10gen for a 1 day “db design sanity check and design tuning” session. Email [email_address] 10gen is hiring in Bay Area and New York. Up Next 11:00-11:30 MongoDB and the Democratic Party -- A Case Study How Sunlight Labs Uses MongoDB