Upgrade to Pro — share decks privately, control downloads, hide ads and more …

meeteor-mongodb.pdf

Brandon Hilkert
April 11, 2012
300

 meeteor-mongodb.pdf

Brandon Hilkert

April 11, 2012
Tweet

Transcript

  1. document store great for comparisons if attributes are contained no

    more joins...sort of Wednesday, April 11, 12
  2. data types Users id name email location 3 “Brandon” “[email protected]

    “Philly” User_Interests id user_id interest_id 1 3 4 Interests id name 4 “HTML” mysql many-to-many Wednesday, April 11, 12
  3. data types Users id name email location interests 3 “Brandon”

    [email protected]” “Philly” [“Ruby”, “MongoDB”] mongodb more NATURAL? User.all(interests: “MongoDB”) array Wednesday, April 11, 12
  4. embedded documents Users id name email location 3 “Brandon” “[email protected]

    “Philly” User_Jobs id user_id job_id 1 3 4 Jobs id employer_id position description 4 7 “Developer” “Web” many-to-many Employers id name location industry 7 “Meeteor” “Philly” “Internet” mysql Wednesday, April 11, 12
  5. embedded documents mongodb class User include MongoMapper::Document key :first_name, String

    key :last_name, String key :headline, String key :email, String many :jobs end class Job include MongoMapper::EmbeddedDocument key :employer, String key :position, String key :description, String key :industry, String end Wednesday, April 11, 12
  6. embedded documents mongodb Users id name email location jobs user.jobs.first.employer

    => “Meeteor” 3 “Brandon” “[email protected]” “Philly” [{:_id => BSON::ObjectId('4e4efad0d052fc3ea0009a7a'), :employer => “Meeteor”, :position => “Founder”, :description => “Create networking application”, :industry => “Internet” }] embedded document Wednesday, April 11, 12
  7. RESULTS matching guru 2 queries with a crap load of

    joins 2 SIMPLE queries Wednesday, April 11, 12
  8. how to not make life miserable after converting... slow queries

    indexing db.system.profile.find({millis:{$gt:2000}}).sort({$natural:-1}) User.ensure_index(:interests) User.ensure_index("jobs.employer") AnalyticLog.ensure_index([[:user_id, 1], [:type, 1]]) Wednesday, April 11, 12