SlideShare a Scribd company logo
10/19/12                                                          Introduction to MongoDB and Ruby




                                 INTRODUCTION TO MONGODB AND RUBY
                                                                  Gary J. Murakami, Ph.D.

                                                          Lead Engineer & Ruby Evangelist
                                                          10gen (the MongoDB company)
                                                              gary.murakami@10gen.com

                                                             Tuesday, September 25, 2012


                                https://github.com/gjmurakami-10gen/talk-mother-lode




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      1/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                         THE CALIFORNIA GOLD RUSH OF 1849




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      2/26
10/19/12                                                          Introduction to MongoDB and Ruby




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      3/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                             MONGODB: RUBY'S MOTHER LODE
                                                                                        Ruby is a gem of a programming
                                                                                                    language
                                                                                           dynamic, multi-paradigm
                                                                                        expressive, powerful, enjoyable



                                                                                   MongoDB is the mother lode of DBs
                                                                                   BSON documents, high-performance
                                                                                     indexing, replication, sharding
                                                                                      flexible, powerful, enjoyable



                                                    Ruby and MongoDB are well matched




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                                           4/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                  OUTFITTING BEYOND YOUR PICKAXE BOOK
                                                       MAC OS X - MONGODB QUICKSTART
                         $be udt
                          rw pae
                         $be isalmnob
                          rw ntl ogd
                         $mno
                          ogd



                                           RUBY DRIVER SETUP - RUBY LANGUAGE CENTER
                         $gmisalmno
                          e ntl og
                         $gmisalbo_x
                          e ntl snet



                                                                                Gemfile
                         gm'og'
                         e mno
                         gm'snet
                         e bo_x'



                                                RUBYMINE
                      IDE includes support for Mongoid and
                                    MongoDB




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      5/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                        LET'S DIG IN
                                                            TWITTER FRIENDS - LOAD USERS
                          rqie'og'
                          eur mno
                          rqie'tplet
                          eur htcin'
                          rqie'sn
                          eur jo'

                          sre_ae=AG[]| 'ayuaai
                          cennm   RV0 | grmrkm'
                          finsisui="tp:/p.wte.o//red/d.sncro=1sre_ae#sre_ae"
                          red_d_r    hts/aititrcm1finsisjo?usr-&cennm={cennm}
                          fin_d =JO.as(TPletgtfinsisui.oy[is]
                          redis   SNpreHTCin.e(red_d_r)bd)'d'



                  a few lines of Ruby gets and parses JSON data from the web - twitter API
                                                       libraries/gems
                                                           mongo, bson, bson_ext
                                                           httpclient, json
                                                       language capability
                                                           method call chaining




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      6/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                               TWITTER FRIENDS - LOAD USERS (CONTINUED)
                          cneto =Mno:oncinnw
                           oncin  og:Cneto.e
                          d =cneto[titr]
                           b oncin'wte'
                          cleto =d[ues]
                           olcin  b'sr'

                          fin_d.ahsie10 d |d|#bs patcs
                          redisec_lc(0) o is   et rcie
                            ueslou_r ="tp:/p.wte.o//sr/okpjo?sri={d.on''}
                             sr_okpui  hts/aititrcm1ueslou.snue_d#isji(,)"
                            rsos =HTCin.e(sr_okpui
                             epne  TPletgtueslou_r)

                               dc =JO.as(epnebd)#hg-ee ojcs-Aryo Hse
                                os  SNprersos.oy  ihlvl bet   ra f ahs
                               dc.ah|o|dc'i' =dc'd] #ue sple _d
                                osec{dc o[_d]  o[i'}  sr upid i
                               cleto.netdc,:ae= tu)#n shm!-bl isr -bs patcs
                                olcinisr(os sf > re  o cea   uk net  et rcie
                          ed
                          n
                          pt "sr:{olcincut"
                          us ues#cleto.on}



                      a small number of lines load JSON data from the web into a collection
                                              DB connection, database, collection
                                              docs - Ruby Array of Hashes from JSON parsing
                                              doc primary _id set by user or driver
                                              collection bulk insert and safe mode
                                              collection count




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      7/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                  HITTING PAYDIRT
                                               TWITTER TOP 10 USERS BY FOLLOWERS COUNT
                          ues=Mno:oncinnw'wte'[ues]
                          sr   og:Cneto.e[titr]'sr'

                          uesfn(} :ot= {floescut - } :ii = 1)ec d |o|
                          sr.id{, sr >    olwr_on: 1 , lmt > 0.ah o dc
                             pt dcvle_t'olwr_on' 'cennm'.on"t)
                              us o.ausa(floescut, sre_ae)ji("
                          ed
                          n



                                                          a simple query with sort and limit
                                      find - cursor enumerable
                                      expressed in Ruby code
                                      driver serializes into BSON and Mongo Wire Protocol
                                      no text language generation or parsing
                         1023
                         491             Dobx
                                          rpo
                         202
                         59              MnoB
                                          ogD
                         97
                         04              ocn
                                          so
                         84
                         18              risof
                                          alcn
                         70
                         32              sf3
                                          p1
                         47
                         34              1gn
                                          0e
                         25
                         29              khdrw
                                          cooo
                         12
                         95              rt
                                          i
                         19
                         25              der
                                          mr
                         14
                         18              arnekan
                                          aohcmn




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      8/26
10/19/12                                                           Introduction to MongoDB and Ruby




                                                                   DIGGING DEEPER
                                                      TWITTER - LOAD TWEETS (SIMPLIFIED)
                          d =Mno:oncinnw'wte'
                           b  og:Cneto.e[titr]
                          ues=d[ues]
                           sr   b'sr'
                          tet =d[tet'
                           wes  b'wes]
                          tet.nueidx'sri' #dtntto t seiysbil
                           wesesr_ne(ue.d)  o oain o pcf ufed

                        uesfn(} {ils {d tu,sre_ae tu,snei:tu})ec d |sr
                        sr.id{, fed: i: re cennm: re ic_d re}.ah o ue|
                          titrue_ieieui= "tp:/p.wte.o//ttssue_ieiejo?sri={s
                           wte_srtmln_r    hts/aititrcm1saue/srtmln.snue_d#u
                     e[i'}cut20icuerstu&otiuo_eal=re
                      r'd]&on=0&nld_t=recnrbtrdtistu"
                          titrue_ieieui+ "ic_d#ue[snei'} i ue[snei'
                           wte_srtmln_r = snei={sr'ic_d]" f sr'ic_d]
                          rsos =HTCin.e(wte_srtmln_r)
                           epne  TPletgttitrue_ieieui

                               dc =JO.as(epnebd)#hg-ee ojcs
                                os  SNprersos.oy   ihlvl bet
                               dc.ah|o|dc'i' =dc'd] #ue sple _d
                                osec{dc o[_d]   o[i'}  sr upid i
                               tet.netdc,:otneo_ro = tu)#bl isr
                                wesisr(os cniu_nerr > re    uk net
                               uesudt(_d ue[_d],{$e'= {snei'= dc.at'd]}
                                sr.pae{i: sr'i'} 'st > 'ic_d > osls[i'})
                               pt tet.on(qey= {ue.d = ue[i'}
                                us wescut:ur > 'sri' > sr'd])
                          ed
                          n
                          pt "wes#tet.on}
                          us tet:{wescut"



                                           a small number of lines loads and records tweets
                                                                  indexing - secondary indexes
                                                                  retrieving a subset of fields
                                                                  update - record since_id
                                                                  count with query selector


file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                       9/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                 TWITTER TOP 10 TWEETS FOR MONGODB BY RETWEET_COUNT
                          tet =Mno:oncinnw'wte'[tet'
                          wes  og:Cneto.e[titr]'wes]

                          sre_ae='ogD'
                          cennm  MnoB

                        tet.id{ue.cennm'= sre_ae,:ot= {rtetcut - } :ii = 1)ec
                        wesfn('srsre_ae > cennm} sr >    ewe_on: 1 , lmt > 0.ah
                     d |o|
                      o dc
                           pt dcvle_t'ewe_on' 'et)ji("
                            us o.ausa(rtetcut, tx'.on"t)
                        ed
                        n



                                         a simple query with a query selector, sort and limit
                                              MongoDB query language
                                              dot notation for nested sub-document fields
                       12#ogD v. rlae ht:/.os6z7
                        7 MnoB 22 eesd tp/tc/NRcD
                       7 #ogD2o2ofcal rlae,w Avne AgeainFaeok MliDt Cne Dpomn
                        7 mnoBdt fiily eesd / dacd grgto rmwr, ut-aa etr elyet
                     +60nwfaue ht:/.oDSWw
                       0 e etrs tp/tc/MdGN
                       5 Anucn fe oln MnoBcass ht:/.oRobl
                        9 nonig re nie ogD lse. tp/tc/IA77
                       3 R @mkl:Itouigmnop afotn fr#ogD' qeypoie hts/tc/OSsW
                        0 T jioa nrdcn ogq:    rned o MnoBs ur rflr tp:/.oRCz6
                       2 Sg u frfe oln MnoBcusssatn i Otbrht:/.oI6QN
                        9 in p o re nie ogD ore trig n coe tp/tc/m84M
                       2 100 hv sge u frfe MnoBtann snetecusswr anucdtdyht:/.o
                        4 ,0+ ae ind p o re ogD riig ic h ore ee none oa tp/tc
                    /IxHt
                     oNf1
                       2 HwDse bitabgdt pafr o asatpbde uigMnoB ht:/.o8Wy7
                        2 o iny ul   i aa ltom n  tru ugt sn ogD. tp/tc/q5cT
                       2 #ogD2o2 aalbefrdwla.ht:/.okGUh
                        1 mnoBdt, vial o onod tp/tc/chDI
                       1 MnoBSadn Vsaie ht:/.ooI0j aohrpouto #0eLb
                        9 ogD hrig iulzr tp/tc/nG8v nte rdc f 1gnas
                       1 MnoBJv Die 290rlae ht:/.oUvoY
                        6 ogD aa rvr .. eesd tp/tc/DZAV




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      10/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                    STRIKING GOLD
                                                                     BSON - BINARY JSON
                                                                    http://bsonspec.org/

                               {BO" [aeoe,50,18]
                                "SN: "wsm" .5 96}                                  →
                               "x1x0x0x0
                                3000
                               0BO0
                                x4SNx0
                               &x0x0x0
                                000
                               00x0x8x0x0x0wsm0
                                x200000aeoex0
                               01x0333x4
                                x103331@
                               12x0x2x7x0x0
                                x00c000
                               0
                                x0
                               0"
                                x0



                         1. base types extended to match modern programming languages
                         2. transfer over wire - Mongo Wire Protocol
                                request payload includes query and documents to server
                                response and documents to client
                         3. store on server disk
                         4. index on server
                              fast - no parsing, no server-side data repackaging to disk



file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      11/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                          REPLICA SETS
                                                            multiple database server nodes
                                           one primary member, many secondary members




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      12/26
10/19/12                                                          Introduction to MongoDB and Ruby


                                                  high availability
                                                      auto-failover via election by majority
                                                      write concern
                                                  read scaling - read preferences

                                                  backups
                                                  upgrades
                                                  use (hidden) replica for secondary workload
                                                      analytics
                                                      data-processing
                                                      integration with external systems




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      13/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                              SHARDING




                                                  horizontal scaling across multiple nodes
file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      14/26
10/19/12                                                          Introduction to MongoDB and Ruby


                                                  horizontal scaling across multiple nodes
                                                      automatic balancing
                                                      failover - each shard can be a replica set
                                                  shard key - partition by range
                                                  chunks up to 64MB
                                                  routing processes - mongos




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      15/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                      NUGGETS - MORE MONGODB FEATURES
                 mongo shell
                    JavaScript, native for server-side processing
                    highly recommended for development and administration
                 map/reduce
                    batch processing of data and aggregation operations
                 aggregation framework
                    calculate aggregated values without having to use map-reduce
                    pipeline, operators, expressions
                 GridFS
                    specification for storing large files in MongoDB chunks usually 256KB
                 Capped collections
                    fixed sized collections that have a very high performance auto-FIFO age-
                    out feature
                 Hadoop connector
                    reading MongoDB data into Hadoop as well as writing map/reduce results
                    back out




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      16/26
10/19/12                                                          Introduction to MongoDB and Ruby




                     FULL-BORE MINING WITH WEB FRAMEWORKS
                                                        Ruby on Rails, Sinatra, etc.
                                         MONGOMAPPER ODM - JOHN NUNEMAKER
                               casUe
                                ls sr
                                  icueMnoapr:ouet
                                   nld ogMpe:Dcmn
                                  ky:ae Srn
                                   e nm, tig
                                  ky:g, Itgr
                                   e ae  nee
                                  mn :obe
                                   ay hbis
                               ed
                                n

                               casHby
                                ls ob
                                  icueMnoapr:meddouet
                                   nld ogMpe:EbdeDcmn
                                  ky:ae
                                   e nm,  Srn
                                           tig
                                  ky:tre,Tm
                                   e satd ie
                               ed
                                n

                               ue =Ue.e(nm = 'rno'
                                sr  srnw:ae > Badn)
                               ue.obe.ul(nm = 'rgamn' :tre = 1.er.g)
                                srhbisbid:ae > Pormig, satd > 0yasao
                               ue.ae
                                srsv!

                               Ue.hr(nm = 'rno'.is
                                srwee:ae > Badn)frt



                                    simplified model different from ActiveRecord
                                    good example for Ruby metaprogramming
                                    small is beautiful



file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      17/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                         MONGOID ODM - DURRAN JORDAN
                               casAts
                                ls rit
                                  icueMnod:ouet
                                   nld ogi:Dcmn
                                  fed:ae tp:Srn
                                   il nm, ye tig
                                  ebd_ay:ntuet
                                   mesmn isrmns
                               ed
                                n

                               casIsrmn
                                ls ntuet
                                  icueMnod:ouet
                                   nld ogi:Dcmn
                                  fed:ae tp:Srn
                                   il nm, ye tig
                                  ebde_n:rit
                                   meddi ats
                               ed
                                n

                               sd=Ats.hr(ae "y Vcos)btenae 1.2)frt
                                y  ritweenm: Sd iiu".ewe(g: 8.5.is
                               sdisrmnscet(ae "as)
                                y.ntuet.raenm: Bs"
                               sdwt(aaae "ad" ssin "akp)sv!
                                y.ihdtbs: bns, eso: bcu".ae



                    documents
                    persistence
                    querying
                    ActiveModel relations (belongs_to, has_one, has_many, habtm)
                    nested attributes
                    validation
                    indexing
                    extras



file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      18/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                     MOPED DRIVER - BERNERD SCHAEFER
                               ssin=Mpd:eso.e( "2...:71"]
                                eso  oe:Ssinnw[ 17001207 )
                               ssinue"cots"
                                eso.s eh_et

                               ssinwt(ae tu)d |ae
                                eso.ihsf: re o sf|
                               sf[atss.netnm:"y Vcos)
                                ae:rit]isr(ae Sd iiu"
                               ed
                                n

                               ssin:rit]fn(ae "y Vcos)udt($uh= {isrmns {nm:"as })
                                eso[atss.idnm: Sd iiu".pae:ps >  ntuet:  ae Bs" }



                   a MongoDB driver for Ruby which exposes a simple, elegant, and fast API
                               fast, thread-safe, uses sidekiq
                               pure Ruby - no C extensions
                               metaprogramming - extends standard classes
                               Ruby > 1.9
                               used by Mongoid 3




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      19/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                  JRUBY
                                The Best of the JVM
                                   High performance
                                   Real threading - multi-core parallelism
                                   Vast array of libraries

                                It's Just Ruby
                                     Ruby 1.8.7 & 1.9.2 compatible
                                     Both versions in single install

                                bson_java
                                Mongo Hadoop connector




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      20/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                           FOOL'S GOLD - RDBMS CASE STUDY
                                               ADOBE PHOTOSHOP LIGHTROOM
                                                    "Lightroom 3 Catalog.lrcat"
                                           0.5 GB
                                           66 Sqlite3 tables
                                           20 tables with column image INTEGER
                                           can be loaded with 40 lines of Ruby
                                           can be reduced to 1 image collection
                                                THE COST OF USING RDBMS FOR PERSISTENCE
                              RDBMS flattened and normalized our data into rigid tables
                              RDBMS costs O(10**6) - O(1000000) and more with many joins
                                Memory O(10**9/sec) - O(1000000000)
                                RDBMS O(10**3/sec) - O(1000)




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      21/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                  THE MOTHER LODE
                                                                     MONGODB SUMMARY
                                               replica sets for high availability
                                               sharded clusters for scaling

                                               very high performance
                                                  secondary indices
                                                  BSON is fast for transfer, storage, queries
                                                  server-side processing
                                                       map-reduce, aggregation
                                                       Hadoop connector
                                               very low cost - open source - community




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      22/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                                                  MONGODB CONCLUSION
                                                   enjoyable software development
                                                       10gen and Moped Ruby drivers
                                                       MongoMapper and Mongoid ODMs
                                                       no schema migrations forced

                                                   well-matched to programming languages
                                                      bigger data
                                                      Ruby and objects




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      23/26
10/19/12                                                          Introduction to MongoDB and Ruby




                                             ANNOUNCEMENT AND QUESTIONS
                                                 MONGODB AND RUBY BLOGGING CONTEST
                                                                               Objective

                                  Write about best practices for using MongoDB with Ruby.

                                           Post your blog posts in the comments section of
                                          this blog post by October 10 to be entered to win.

               http://blog.10gen.com/post/32158163299/mongodb-and-ruby-blogging-
                                              contest
                              Google: mongodb and ruby blogging contest




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                      24/26
10/19/12                                                           Introduction to MongoDB and Ruby




                                                                          THANK YOU
                                                                  AND MAY YOU STRIKE GOLD
                                                    {
                                                         nm:"ayJ Mrkm,P..,
                                                          ae Gr . uaai hD"
                                                         tte "edEgne adRb Eagls"
                                                          il: La nier n uy vneit,
                                                         cmay "0e (h MnoBcmay"
                                                          opn: 1gn te ogD opn),
                                                         poe "-6-3-85x05,
                                                          hn: 1862781 81"
                                                         mbl:"-0-8-61,
                                                          oie 1987762"
                                                         eal "aymrkm@0e.o"
                                                          mi: gr.uaai1gncm,
                                                         i:"juaai(I),
                                                          m gmrkm AM"
                                                         titr "GrMrkm"
                                                          wte: @ayuaai,
                                                         bo:"ryhswie.lgptcm,
                                                          lg gagotrtrboso.o"
                                                         wbie "w.oelog,
                                                          est: wwnbl.r"
                                                         lnei:"w.ikdncmpbgr-uaai13a37,
                                                          ikdn wwlnei.o/u/aymrkm//6/2"
                                                         fcbo:"aeokcmgr..uaai
                                                          aeok fcbo.o/ayjmrkm"
                                                    }



                                  https://github.com/gjmurakami-10gen/talk-mother-lode
                                  git://github.com/gjmurakami-10gen/talk-mother-lode.git

                                   MongoDB
                                   Ruby Language Center
                                   Github mongodb/mongo-ruby-driver




file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/                                       25/26

More Related Content

What's hot (19)

PDF
Javascript - Getting started | DevCom ISITCom
Hamdi Hmidi
 
ZIP
Fast & Scalable Front/Back-ends using Ruby, Rails & XMPP
Pradeep Elankumaran
 
PDF
BRAINREPUBLIC - Powered by no-SQL
Andreas Jung
 
PDF
Introduction to Web Designing
Kailaash Balachandran
 
PDF
Modern web application devlopment workflow
Hamdi Hmidi
 
PDF
Getting Started: The Environment
Ibrahim Abdel Fattah Mohamed
 
PDF
04 web optimization
Nguyen Duc Phu
 
PDF
ApacheCon09: Avro
Cloudera, Inc.
 
PDF
Ruby tutorial
Ánh Nguyễn
 
PDF
NoSQL for great good [hanoi.rb talk]
Huy Do
 
PPTX
spdy
Kensaku Komatsu
 
PPTX
Part One: Building Web Apps with the MERN Stack
MongoDB
 
PDF
Post-relational databases: What's wrong with web development? v3
Dobrica Pavlinušić
 
PDF
MongoDB
Serdar Buyuktemiz
 
PDF
Introduction to protocol buffer
Tim (文昌)
 
PDF
PHP and Web Services
Bruno Pedro
 
PDF
Mongodb
Scott Motte
 
PDF
Developing cross platform desktop application with Ruby
Anis Ahmad
 
PDF
MongoDB
SPBRUBY
 
Javascript - Getting started | DevCom ISITCom
Hamdi Hmidi
 
Fast & Scalable Front/Back-ends using Ruby, Rails & XMPP
Pradeep Elankumaran
 
BRAINREPUBLIC - Powered by no-SQL
Andreas Jung
 
Introduction to Web Designing
Kailaash Balachandran
 
Modern web application devlopment workflow
Hamdi Hmidi
 
Getting Started: The Environment
Ibrahim Abdel Fattah Mohamed
 
04 web optimization
Nguyen Duc Phu
 
ApacheCon09: Avro
Cloudera, Inc.
 
Ruby tutorial
Ánh Nguyễn
 
NoSQL for great good [hanoi.rb talk]
Huy Do
 
Part One: Building Web Apps with the MERN Stack
MongoDB
 
Post-relational databases: What's wrong with web development? v3
Dobrica Pavlinušić
 
Introduction to protocol buffer
Tim (文昌)
 
PHP and Web Services
Bruno Pedro
 
Mongodb
Scott Motte
 
Developing cross platform desktop application with Ruby
Anis Ahmad
 
MongoDB
SPBRUBY
 

Similar to Introduction to MongoDB and Ruby (20)

PDF
Introduction to using MongoDB with Ruby
Jonathan Holloway
 
PPTX
Gaasdm
Josh Bailey
 
PDF
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDB
r1dotmy
 
PDF
The elephant in the room mongo db + hadoop
iammutex
 
PDF
From Zero to Mongo, Art.sy Experience w/ MongoDB
Daniel Doubrovkine
 
PDF
Middleware as Code with mruby
Hiroshi SHIBATA
 
PDF
The Future of Dependency Management for Ruby
Hiroshi SHIBATA
 
PDF
Invitation to mongo db @ Rakuten TechTalk
Ryuji Tamagawa
 
PDF
Middleware as Code with mruby
Hiroshi SHIBATA
 
PPT
Ruby on Rails 3 Day BC
Northwest Independent Ruby Development
 
PPTX
Mongo db
Yıldırım Tam
 
PPTX
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
Tobias Trelle
 
PDF
MongoDB and Node.js
Norberto Leite
 
PPSX
Mongodb
foliba
 
PDF
PRUG Meetup - RGSoC Team Rubinius
Akanksha Agrawal
 
PDF
Design of a_dsl_by_ruby_for_heavy_computations
Koichi Fujikawa
 
PDF
Mongo db bangalore
MongoDB
 
PPTX
Webinar: Building Your First App in Node.js
MongoDB
 
PPTX
Webinar: Building Your First App in Node.js
MongoDB
 
PDF
Mongodb
Paulo Fagundes
 
Introduction to using MongoDB with Ruby
Jonathan Holloway
 
Gaasdm
Josh Bailey
 
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDB
r1dotmy
 
The elephant in the room mongo db + hadoop
iammutex
 
From Zero to Mongo, Art.sy Experience w/ MongoDB
Daniel Doubrovkine
 
Middleware as Code with mruby
Hiroshi SHIBATA
 
The Future of Dependency Management for Ruby
Hiroshi SHIBATA
 
Invitation to mongo db @ Rakuten TechTalk
Ryuji Tamagawa
 
Middleware as Code with mruby
Hiroshi SHIBATA
 
Mongo db
Yıldırım Tam
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
Tobias Trelle
 
MongoDB and Node.js
Norberto Leite
 
Mongodb
foliba
 
PRUG Meetup - RGSoC Team Rubinius
Akanksha Agrawal
 
Design of a_dsl_by_ruby_for_heavy_computations
Koichi Fujikawa
 
Mongo db bangalore
MongoDB
 
Webinar: Building Your First App in Node.js
MongoDB
 
Webinar: Building Your First App in Node.js
MongoDB
 
Ad

More from MongoDB (20)

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

Recently uploaded (20)

PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 

Introduction to MongoDB and Ruby

  • 1. 10/19/12 Introduction to MongoDB and Ruby INTRODUCTION TO MONGODB AND RUBY Gary J. Murakami, Ph.D. Lead Engineer & Ruby Evangelist 10gen (the MongoDB company) [email protected] Tuesday, September 25, 2012 https://github.com/gjmurakami-10gen/talk-mother-lode file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 1/26
  • 2. 10/19/12 Introduction to MongoDB and Ruby THE CALIFORNIA GOLD RUSH OF 1849 file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 2/26
  • 3. 10/19/12 Introduction to MongoDB and Ruby file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 3/26
  • 4. 10/19/12 Introduction to MongoDB and Ruby MONGODB: RUBY'S MOTHER LODE Ruby is a gem of a programming language dynamic, multi-paradigm expressive, powerful, enjoyable MongoDB is the mother lode of DBs BSON documents, high-performance indexing, replication, sharding flexible, powerful, enjoyable Ruby and MongoDB are well matched file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 4/26
  • 5. 10/19/12 Introduction to MongoDB and Ruby OUTFITTING BEYOND YOUR PICKAXE BOOK MAC OS X - MONGODB QUICKSTART $be udt rw pae $be isalmnob rw ntl ogd $mno ogd RUBY DRIVER SETUP - RUBY LANGUAGE CENTER $gmisalmno e ntl og $gmisalbo_x e ntl snet Gemfile gm'og' e mno gm'snet e bo_x' RUBYMINE IDE includes support for Mongoid and MongoDB file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 5/26
  • 6. 10/19/12 Introduction to MongoDB and Ruby LET'S DIG IN TWITTER FRIENDS - LOAD USERS rqie'og' eur mno rqie'tplet eur htcin' rqie'sn eur jo' sre_ae=AG[]| 'ayuaai cennm RV0 | grmrkm' finsisui="tp:/p.wte.o//red/d.sncro=1sre_ae#sre_ae" red_d_r hts/aititrcm1finsisjo?usr-&cennm={cennm} fin_d =JO.as(TPletgtfinsisui.oy[is] redis SNpreHTCin.e(red_d_r)bd)'d' a few lines of Ruby gets and parses JSON data from the web - twitter API libraries/gems mongo, bson, bson_ext httpclient, json language capability method call chaining file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 6/26
  • 7. 10/19/12 Introduction to MongoDB and Ruby TWITTER FRIENDS - LOAD USERS (CONTINUED) cneto =Mno:oncinnw oncin og:Cneto.e d =cneto[titr] b oncin'wte' cleto =d[ues] olcin b'sr' fin_d.ahsie10 d |d|#bs patcs redisec_lc(0) o is et rcie ueslou_r ="tp:/p.wte.o//sr/okpjo?sri={d.on''} sr_okpui hts/aititrcm1ueslou.snue_d#isji(,)" rsos =HTCin.e(sr_okpui epne TPletgtueslou_r) dc =JO.as(epnebd)#hg-ee ojcs-Aryo Hse os SNprersos.oy ihlvl bet ra f ahs dc.ah|o|dc'i' =dc'd] #ue sple _d osec{dc o[_d] o[i'} sr upid i cleto.netdc,:ae= tu)#n shm!-bl isr -bs patcs olcinisr(os sf > re o cea uk net et rcie ed n pt "sr:{olcincut" us ues#cleto.on} a small number of lines load JSON data from the web into a collection DB connection, database, collection docs - Ruby Array of Hashes from JSON parsing doc primary _id set by user or driver collection bulk insert and safe mode collection count file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 7/26
  • 8. 10/19/12 Introduction to MongoDB and Ruby HITTING PAYDIRT TWITTER TOP 10 USERS BY FOLLOWERS COUNT ues=Mno:oncinnw'wte'[ues] sr og:Cneto.e[titr]'sr' uesfn(} :ot= {floescut - } :ii = 1)ec d |o| sr.id{, sr > olwr_on: 1 , lmt > 0.ah o dc pt dcvle_t'olwr_on' 'cennm'.on"t) us o.ausa(floescut, sre_ae)ji(" ed n a simple query with sort and limit find - cursor enumerable expressed in Ruby code driver serializes into BSON and Mongo Wire Protocol no text language generation or parsing 1023 491 Dobx rpo 202 59 MnoB ogD 97 04 ocn so 84 18 risof alcn 70 32 sf3 p1 47 34 1gn 0e 25 29 khdrw cooo 12 95 rt i 19 25 der mr 14 18 arnekan aohcmn file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 8/26
  • 9. 10/19/12 Introduction to MongoDB and Ruby DIGGING DEEPER TWITTER - LOAD TWEETS (SIMPLIFIED) d =Mno:oncinnw'wte' b og:Cneto.e[titr] ues=d[ues] sr b'sr' tet =d[tet' wes b'wes] tet.nueidx'sri' #dtntto t seiysbil wesesr_ne(ue.d) o oain o pcf ufed uesfn(} {ils {d tu,sre_ae tu,snei:tu})ec d |sr sr.id{, fed: i: re cennm: re ic_d re}.ah o ue| titrue_ieieui= "tp:/p.wte.o//ttssue_ieiejo?sri={s wte_srtmln_r hts/aititrcm1saue/srtmln.snue_d#u e[i'}cut20icuerstu&otiuo_eal=re r'd]&on=0&nld_t=recnrbtrdtistu" titrue_ieieui+ "ic_d#ue[snei'} i ue[snei' wte_srtmln_r = snei={sr'ic_d]" f sr'ic_d] rsos =HTCin.e(wte_srtmln_r) epne TPletgttitrue_ieieui dc =JO.as(epnebd)#hg-ee ojcs os SNprersos.oy ihlvl bet dc.ah|o|dc'i' =dc'd] #ue sple _d osec{dc o[_d] o[i'} sr upid i tet.netdc,:otneo_ro = tu)#bl isr wesisr(os cniu_nerr > re uk net uesudt(_d ue[_d],{$e'= {snei'= dc.at'd]} sr.pae{i: sr'i'} 'st > 'ic_d > osls[i'}) pt tet.on(qey= {ue.d = ue[i'} us wescut:ur > 'sri' > sr'd]) ed n pt "wes#tet.on} us tet:{wescut" a small number of lines loads and records tweets indexing - secondary indexes retrieving a subset of fields update - record since_id count with query selector file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 9/26
  • 10. 10/19/12 Introduction to MongoDB and Ruby TWITTER TOP 10 TWEETS FOR MONGODB BY RETWEET_COUNT tet =Mno:oncinnw'wte'[tet' wes og:Cneto.e[titr]'wes] sre_ae='ogD' cennm MnoB tet.id{ue.cennm'= sre_ae,:ot= {rtetcut - } :ii = 1)ec wesfn('srsre_ae > cennm} sr > ewe_on: 1 , lmt > 0.ah d |o| o dc pt dcvle_t'ewe_on' 'et)ji(" us o.ausa(rtetcut, tx'.on"t) ed n a simple query with a query selector, sort and limit MongoDB query language dot notation for nested sub-document fields 12#ogD v. rlae ht:/.os6z7 7 MnoB 22 eesd tp/tc/NRcD 7 #ogD2o2ofcal rlae,w Avne AgeainFaeok MliDt Cne Dpomn 7 mnoBdt fiily eesd / dacd grgto rmwr, ut-aa etr elyet +60nwfaue ht:/.oDSWw 0 e etrs tp/tc/MdGN 5 Anucn fe oln MnoBcass ht:/.oRobl 9 nonig re nie ogD lse. tp/tc/IA77 3 R @mkl:Itouigmnop afotn fr#ogD' qeypoie hts/tc/OSsW 0 T jioa nrdcn ogq: rned o MnoBs ur rflr tp:/.oRCz6 2 Sg u frfe oln MnoBcusssatn i Otbrht:/.oI6QN 9 in p o re nie ogD ore trig n coe tp/tc/m84M 2 100 hv sge u frfe MnoBtann snetecusswr anucdtdyht:/.o 4 ,0+ ae ind p o re ogD riig ic h ore ee none oa tp/tc /IxHt oNf1 2 HwDse bitabgdt pafr o asatpbde uigMnoB ht:/.o8Wy7 2 o iny ul i aa ltom n tru ugt sn ogD. tp/tc/q5cT 2 #ogD2o2 aalbefrdwla.ht:/.okGUh 1 mnoBdt, vial o onod tp/tc/chDI 1 MnoBSadn Vsaie ht:/.ooI0j aohrpouto #0eLb 9 ogD hrig iulzr tp/tc/nG8v nte rdc f 1gnas 1 MnoBJv Die 290rlae ht:/.oUvoY 6 ogD aa rvr .. eesd tp/tc/DZAV file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 10/26
  • 11. 10/19/12 Introduction to MongoDB and Ruby STRIKING GOLD BSON - BINARY JSON http://bsonspec.org/ {BO" [aeoe,50,18] "SN: "wsm" .5 96} → "x1x0x0x0 3000 0BO0 x4SNx0 &x0x0x0 000 00x0x8x0x0x0wsm0 x200000aeoex0 01x0333x4 x103331@ 12x0x2x7x0x0 x00c000 0 x0 0" x0 1. base types extended to match modern programming languages 2. transfer over wire - Mongo Wire Protocol request payload includes query and documents to server response and documents to client 3. store on server disk 4. index on server fast - no parsing, no server-side data repackaging to disk file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 11/26
  • 12. 10/19/12 Introduction to MongoDB and Ruby REPLICA SETS multiple database server nodes one primary member, many secondary members file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 12/26
  • 13. 10/19/12 Introduction to MongoDB and Ruby high availability auto-failover via election by majority write concern read scaling - read preferences backups upgrades use (hidden) replica for secondary workload analytics data-processing integration with external systems file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 13/26
  • 14. 10/19/12 Introduction to MongoDB and Ruby SHARDING horizontal scaling across multiple nodes file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 14/26
  • 15. 10/19/12 Introduction to MongoDB and Ruby horizontal scaling across multiple nodes automatic balancing failover - each shard can be a replica set shard key - partition by range chunks up to 64MB routing processes - mongos file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 15/26
  • 16. 10/19/12 Introduction to MongoDB and Ruby NUGGETS - MORE MONGODB FEATURES mongo shell JavaScript, native for server-side processing highly recommended for development and administration map/reduce batch processing of data and aggregation operations aggregation framework calculate aggregated values without having to use map-reduce pipeline, operators, expressions GridFS specification for storing large files in MongoDB chunks usually 256KB Capped collections fixed sized collections that have a very high performance auto-FIFO age- out feature Hadoop connector reading MongoDB data into Hadoop as well as writing map/reduce results back out file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 16/26
  • 17. 10/19/12 Introduction to MongoDB and Ruby FULL-BORE MINING WITH WEB FRAMEWORKS Ruby on Rails, Sinatra, etc. MONGOMAPPER ODM - JOHN NUNEMAKER casUe ls sr icueMnoapr:ouet nld ogMpe:Dcmn ky:ae Srn e nm, tig ky:g, Itgr e ae nee mn :obe ay hbis ed n casHby ls ob icueMnoapr:meddouet nld ogMpe:EbdeDcmn ky:ae e nm, Srn tig ky:tre,Tm e satd ie ed n ue =Ue.e(nm = 'rno' sr srnw:ae > Badn) ue.obe.ul(nm = 'rgamn' :tre = 1.er.g) srhbisbid:ae > Pormig, satd > 0yasao ue.ae srsv! Ue.hr(nm = 'rno'.is srwee:ae > Badn)frt simplified model different from ActiveRecord good example for Ruby metaprogramming small is beautiful file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 17/26
  • 18. 10/19/12 Introduction to MongoDB and Ruby MONGOID ODM - DURRAN JORDAN casAts ls rit icueMnod:ouet nld ogi:Dcmn fed:ae tp:Srn il nm, ye tig ebd_ay:ntuet mesmn isrmns ed n casIsrmn ls ntuet icueMnod:ouet nld ogi:Dcmn fed:ae tp:Srn il nm, ye tig ebde_n:rit meddi ats ed n sd=Ats.hr(ae "y Vcos)btenae 1.2)frt y ritweenm: Sd iiu".ewe(g: 8.5.is sdisrmnscet(ae "as) y.ntuet.raenm: Bs" sdwt(aaae "ad" ssin "akp)sv! y.ihdtbs: bns, eso: bcu".ae documents persistence querying ActiveModel relations (belongs_to, has_one, has_many, habtm) nested attributes validation indexing extras file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 18/26
  • 19. 10/19/12 Introduction to MongoDB and Ruby MOPED DRIVER - BERNERD SCHAEFER ssin=Mpd:eso.e( "2...:71"] eso oe:Ssinnw[ 17001207 ) ssinue"cots" eso.s eh_et ssinwt(ae tu)d |ae eso.ihsf: re o sf| sf[atss.netnm:"y Vcos) ae:rit]isr(ae Sd iiu" ed n ssin:rit]fn(ae "y Vcos)udt($uh= {isrmns {nm:"as }) eso[atss.idnm: Sd iiu".pae:ps > ntuet: ae Bs" } a MongoDB driver for Ruby which exposes a simple, elegant, and fast API fast, thread-safe, uses sidekiq pure Ruby - no C extensions metaprogramming - extends standard classes Ruby > 1.9 used by Mongoid 3 file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 19/26
  • 20. 10/19/12 Introduction to MongoDB and Ruby JRUBY The Best of the JVM High performance Real threading - multi-core parallelism Vast array of libraries It's Just Ruby Ruby 1.8.7 & 1.9.2 compatible Both versions in single install bson_java Mongo Hadoop connector file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 20/26
  • 21. 10/19/12 Introduction to MongoDB and Ruby FOOL'S GOLD - RDBMS CASE STUDY ADOBE PHOTOSHOP LIGHTROOM "Lightroom 3 Catalog.lrcat" 0.5 GB 66 Sqlite3 tables 20 tables with column image INTEGER can be loaded with 40 lines of Ruby can be reduced to 1 image collection THE COST OF USING RDBMS FOR PERSISTENCE RDBMS flattened and normalized our data into rigid tables RDBMS costs O(10**6) - O(1000000) and more with many joins Memory O(10**9/sec) - O(1000000000) RDBMS O(10**3/sec) - O(1000) file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 21/26
  • 22. 10/19/12 Introduction to MongoDB and Ruby THE MOTHER LODE MONGODB SUMMARY replica sets for high availability sharded clusters for scaling very high performance secondary indices BSON is fast for transfer, storage, queries server-side processing map-reduce, aggregation Hadoop connector very low cost - open source - community file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 22/26
  • 23. 10/19/12 Introduction to MongoDB and Ruby MONGODB CONCLUSION enjoyable software development 10gen and Moped Ruby drivers MongoMapper and Mongoid ODMs no schema migrations forced well-matched to programming languages bigger data Ruby and objects file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 23/26
  • 24. 10/19/12 Introduction to MongoDB and Ruby ANNOUNCEMENT AND QUESTIONS MONGODB AND RUBY BLOGGING CONTEST Objective Write about best practices for using MongoDB with Ruby. Post your blog posts in the comments section of this blog post by October 10 to be entered to win. http://blog.10gen.com/post/32158163299/mongodb-and-ruby-blogging- contest Google: mongodb and ruby blogging contest file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 24/26
  • 25. 10/19/12 Introduction to MongoDB and Ruby THANK YOU AND MAY YOU STRIKE GOLD { nm:"ayJ Mrkm,P.., ae Gr . uaai hD" tte "edEgne adRb Eagls" il: La nier n uy vneit, cmay "0e (h MnoBcmay" opn: 1gn te ogD opn), poe "-6-3-85x05, hn: 1862781 81" mbl:"-0-8-61, oie 1987762" eal "[email protected]" mi: gr.uaai1gncm, i:"juaai(I), m gmrkm AM" titr "GrMrkm" wte: @ayuaai, bo:"ryhswie.lgptcm, lg gagotrtrboso.o" wbie "w.oelog, est: wwnbl.r" lnei:"w.ikdncmpbgr-uaai13a37, ikdn wwlnei.o/u/aymrkm//6/2" fcbo:"aeokcmgr..uaai aeok fcbo.o/ayjmrkm" } https://github.com/gjmurakami-10gen/talk-mother-lode git://github.com/gjmurakami-10gen/talk-mother-lode.git MongoDB Ruby Language Center Github mongodb/mongo-ruby-driver file:///Users/gjm/10gen/talk‑mother‑lode/index.html?print‑pdf#/ 25/26