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
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 } )
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?
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