Slide 1

Slide 1 text

歓喜に寄せて

Slide 2

Slide 2 text

» MongoDB is our only data store (technically, S3 is our other store) January 2011

Slide 3

Slide 3 text

» How do you plan to query your data?

Slide 4

Slide 4 text

» N-Gram Search https://github.com/artsy/mongoid_fulltext class Artist include Mongoid::Document include Mongoid::FullTextSearch field :first_name field :last_name def name [first_name, last_name].join(' ') end fulltext_search_in :name end

Slide 5

Slide 5 text

~ 50 of 850 genes MongoDB: A Sparse Hash { Contemporary : 100, Computer Art : 20, Plays With Scale: 80, Humor : 70, Nostalgia : 0, Hairy or Fluffy : 0 }

Slide 6

Slide 6 text

MongoDB: Inheritance in the Database { _type : SoloArtist, birthday : 1929, deathday : 1972 } { _type : ArtCollective founded : 1929 }

Slide 7

Slide 7 text

MongoDB: Cartesian Product { id : BSON::ObjectId(…) color : red, medium : works-on-paper, size : small, price : [0, 12, 48], }

Slide 8

Slide 8 text

MongoDB: from LSH to K-Most Similar Graph { artwork_id : BSON::ObjectId(…) neighbors : [[ BSON::ObjectId(…), score ], … ] } http://www.mit.edu/~andoni/LSH/ http://www.cs.princeton.edu/cass/papers/www11.pdf

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

class User include Mongoid::Document field :account_created, default: false has_many :authentications def account_created? account_created || authentications.any? end end task :migrate do User.where({ :account_created.exists => false }).each do |user| user.update_attributes!({ account_created: user.account_created? }) end end

Slide 11

Slide 11 text

Shard?

Slide 12

Slide 12 text

REST API as little online processing as possible as much offline parallel processing as possible iPad CMS Web

Slide 13

Slide 13 text

» Mongoid Collection Snapshot https://github.com/aaw/mongoid_collection_snapshot as much offline parallel processing as possible

Slide 14

Slide 14 text

Denormalize? https://github.com/logandk/mongoid_denormalize https://github.com/dzello/mongoid_alize

Slide 15

Slide 15 text

» Mongoid Cached JSON https://github.com/dblock/mongoid-cached-json REST API class Widget include Mongoid::CachedJson field :name has_many :gadgets json_fields \ :name => { }, :gadgets => { :type => :reference, :properties => :public } end

Slide 16

Slide 16 text

Throw Birds?

Slide 17

Slide 17 text

rpm_contrib 2.1.9 newrelic_rpm 3.3.3 https://github.com/newrelic/rpm_contrib/pull/16

Slide 18

Slide 18 text

testing models and APIs will save your life class User include Mongoid::Document end class Admin < User end class Representative include Mongoid::Document belongs_to :user, inverse_of: :representative belongs_to :admin , inverse_of: nil end

Slide 19

Slide 19 text

• mongoid-history • carrierwave-mongoid • mongoid_fulltext • mongoid_slug • delayed_job_mongoid • mongoid_collection_snapshot • delayed_job_shallow_mongoid • mongoid-cached-json

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Local MongoDB sudo rm /var/lib/mongodb/mongod.lock Heroku MongoDB small Heroku MongoDB shared replica set MongoHQ dedicted replica set

Slide 22

Slide 22 text

MongoHQ Heroku Heroku & Local mongodump mongodump http://code.dblock.org/a-rake-task-for-copying-mongodb-databases

Slide 23

Slide 23 text

» $15 - $49 per developer / month » 149$ / month for a Small Replica Set » $1345 / month for a Large Replica Set -------- ~ 25K$ / year on database hosting

Slide 24

Slide 24 text

art.sy: http://art.sy twitter: @dblockdotorg blog: http://code.dblock.org email: [email protected] slides on slideshare: http://slideshare.net/dblockdotorg