0
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...
3. Store UUIDs as BinData rather than as strings > help misc b = new BinData(subtype,base64str)  create a BSON BinData val...
4. Field name lengths
4. Use covered compound indexes to create materialized views* * coming soon! -- your current build may not be fast yet > /...
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...
7. Manually padding records obj.padding = “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”; coll.insert(obj); coll.update({_id:obj._id...
8. other things you should be using (checklist) <ul><li>multikeys </li></ul><ul><li>dot notation </li></ul><ul><li>“ fire ...
thanks questions? [email_address] @dmerr Please follow @mongodb on twitter. Sign up with 10gen for a 1 day “db design sani...
Upcoming SlideShare
Loading in...5
×

Tricks

1,595

Published on

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,595
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "Tricks"

  1. 1. Crazy Stuff : Hacks, Internals, and Sneaky Tricks Dwight Merriman 10gen Mongo D.C. Conference
  2. 2. 1. nearly ordered keys have nice properties db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : rand() } )
  3. 3. 1. nearly ordered keys db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : rand() } )
  4. 4. 1. nearly ordered keys db.coll.ensureIndex( { x : 1 } ) db.coll.insert( { x : new Date() } )
  5. 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. 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. 7. 4. Field name lengths
  8. 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. 9. 5. query the replication oplog
  10. 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. 11. 7. Manually padding records obj.padding = “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”; coll.insert(obj); coll.update({_id:obj._id}, { $unset : { padding : 1 } });
  12. 12. 8. other things you should be using (checklist) <ul><li>multikeys </li></ul><ul><li>dot notation </li></ul><ul><li>“ fire and forget” (i.e., don’t call getLastError for noncritical writes) </li></ul><ul><li>upserts </li></ul><ul><li>the HTTP admin page for replica sets </li></ul>
  13. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×