SlideShare una empresa de Scribd logo
1 de 58
Descargar para leer sin conexión
Ruby &
                                                       ^
                              Hands on with MongoDB
                                   Austin on Rails    October 27, 2009




                                                                         WYNNNETHERLAND
Wednesday, October 28, 2009
Wednesday, October 28, 2009
x
                                  No SQL?


                                     x




Wednesday, October 28, 2009
When does NOSQL make sense?
               ★ Your data is stored and retrieved mainly by primary key, without
                 complex joins.
               ★ You have a non-trivial amount of data, and the thought of managing
                 lots of RDBMS shards and replication failure scenarios gives you the fear.


               http://www.metabrew.com/article/anti-rdbms-a-list-of-distributed-key-value-stores/




Wednesday, October 28, 2009
Key value stores
                    Project Voldemort

                                                               me ver  y cool
                    Ringo
                    Scalaris
                                                            So                space
                    Kai
                                                               ojects in this
                    Dynomite
                    MemcacheDB
                                                            pr
                    ThruDB
                    CouchDB
                    Cassandra
                    HBase
                    Hypertable
                    Redis
                    Tokyo Cabinet/Tyrant

                   http://www.metabrew.com/article/anti-rdbms-a-list-of-distributed-key-value-stores/




Wednesday, October 28, 2009
Tokyo Cabinet: Popular with Rubyists, Big in Japan




Wednesday, October 28, 2009
Tokyo Cabinet: Popular with Rubyists, Big in Japan

               ★ Lightning fast
               ★ Works best for at objects
               ★ Tokyo Tyrant for network access


               http://www.igvita.com/2009/02/13/tokyo-cabinet-beyond-key-value-store/




Wednesday, October 28, 2009
More document-oriented solutions



Wednesday, October 28, 2009
Wednesday, October 28, 2009
CouchDB

               Apache CouchDB is a distributed, fault-tolerant and
               schema-free document-oriented database accessible via
               a RESTful HTTP/JSON API.




               http://couchdb.apache.org/


Wednesday, October 28, 2009
Erlang + Javascript



Wednesday, October 28, 2009
Map + reduce



Wednesday, October 28, 2009
Very cool



Wednesday, October 28, 2009
Plenty o’ Ruby to go around



Wednesday, October 28, 2009
Ruby libraries for CouchDB

                CouchRest
                Basic model

                                                         om t he
                RelaxDB
                                                      Fr             ils talk
                                                               on Ra
                CouchPotato
                CouchFoo                              A  ustin
                ActiveCouch

               http://www.slideshare.net/brianthecoder/couchdb




Wednesday, October 28, 2009
Document stores:
                                                      a lmost*
                                 Throw out everything
                              you learned about DB design
                              * more on this later

Wednesday, October 28, 2009
SQL                                             CouchDB

                              Prede ned, explicit schema                           Dynamic, implicit schema



                                                                          Collection of named documents with varying
                                Uniform tables of data
                                                                                           structure


                      Normalized. Objects spread across tables.          Denormalized. Docs usually self contained. Data
                               Duplication reduced.                                    often duplicated.


                    Must know schema to read/write a complete
                                                                                Must know only document name
                                    object



                          Dynamic queries of static schemas                    Static queries of dynamic schemas



                        http://damienkatz.net/files/What is CouchDB.pdf
           http://damienkatz.net/files/What is CouchDB.pdf

Wednesday, October 28, 2009
SQL                                           CouchDB

                              Prede ned, explicit schema                          Dynamic, implicit schema



                                                                         Collection of named documents with varying
                                Uniform tables of data
                                                                                          structure


                      Normalized. Objects spread across tables.
                               Duplication reduced.
                                                               TheDenormalized. Docs usually selfdetails
                                                                   devil'soften duplicated.contained. Data
                                                                                 in the

                    Must know schema to read/write a complete
                                                                              Must know only document name
                                    object



                          Dynamic queries of static schemas                 Static queries of dynamic schemas



                        http://damienkatz.net/files/What is CouchDB.pdf
           http://damienkatz.net/files/What is CouchDB.pdf

Wednesday, October 28, 2009
Wednesday, October 28, 2009
because this is BIG




Wednesday, October 28, 2009
Wednesday, October 28, 2009
Runs like Hayes.
                              Hits like Mays.




Wednesday, October 28, 2009
MongoDB
                              x




Wednesday, October 28, 2009
Let's just skip to here already!



                              x




Wednesday, October 28, 2009
Introducing
               ★ Built For Speedcan be very fast

               ★ Dynamic Queries and Indexes
               ★ Replication and Failover
               ★ Sharding
               ★ Map / Reduce




Wednesday, October 28, 2009
MongoDB is great for
                   ★ Websites
                   ★ Caching
                   ★ High volume, low value
                   ★ High scalability                      stash the hash

                   ★ Storage of program objects and JSON




Wednesday, October 28, 2009
Not as great for
                   ★ Highly transactional
                   ★ Ad-hoc business intelligence
                   ★ Problems requiring SQL




Wednesday, October 28, 2009
Installation
                   ★ mkdir -p /data/db
                   ★ download pre-built for OSX and unzip to /usr/local/
                   ★ cp -R /usr/local/pathtomongo/bin /usr/local/bin

                                                       Ruby driver for MongoDB

                   ★ sudo gem install mongo
                                                             Native C
                   ★ sudo gem install mongo_ext              extensions ( go turbo! )


                   ★ sudo gem install mongo_mapper



Wednesday, October 28, 2009
what's in the box?
               Contents of mongo/bin
                   ★ mongod - The MongoDB server
                   ★ mongo - the JavaScript interactive shell
                   ★ mongoexport - export data as JSON or csv
                   ★ mongoimport - As advertised
                                                                                  was?
                   ★ mongodump - Like mysqldump        why? What did you think it


                   ★ mongorestore - Restore from mongodump les
                   ★ mongos - Auto-sharding module (getting better with every build)



Wednesday, October 28, 2009
Some new terms



Wednesday, October 28, 2009
When I say

                         database


Wednesday, October 28, 2009
When I say     think

                         database    database


Wednesday, October 28, 2009
When I say     think

                         database    database
                                     Well that one isn't new...




Wednesday, October 28, 2009
Databases in MongoDB
                   ★ Made up of multiple collections
                   ★ Are created on-the- y when rst referenced




Wednesday, October 28, 2009
When I say

                         collection


Wednesday, October 28, 2009
When I say       think

                         collection    table


Wednesday, October 28, 2009
Collections in MongoDB
                   ★ Schema-less    but typed!


                   ★ For grouping documents into smaller query sets (speed)
                   ★ Indexable by one or more key
                   ★ Are created on-the- y when rst referenced
                   ★ Capped collections: Fixed size, older records dropped after limit
                     reached




Wednesday, October 28, 2009
When I say

                         document


Wednesday, October 28, 2009
When I say     think

                         document    record or row


Wednesday, October 28, 2009
Document
                   ★ Stored in a collection
                   ★ Can have _id key that works like primary keys in MySQL
                   ★ Supports relationships: subdocument or db reference




Wednesday, October 28, 2009
Document Storage (BSON)
                         { author: 'joe',
                              created: Date('03-28-2009'),
                              title: 'Yet another blog post',
                              text: 'Here is the text...',
                              tags: [ 'example', 'joe' ],
                              comments: [ { author: 'jim', comment: 'I disagree' },
                                          { author: 'nancy', comment: 'Good post' }
                              ]
                         }




    http://www.mongodb.org/display/DOCS/BSON
Wednesday, October 28, 2009
Document Storage (BSON)
                         { author: 'joe',
                              created: Date('03-28-2009'),
                              title: 'Yet another blog post',
                              text: 'Here is the text...',
                              tags: [ 'example', 'joe' ],
                              comments: [ { author: 'jim', comment: 'I disagree' },
                                          { author: 'nancy', comment: 'Good post' }
                              ]
                         }


                  Sure wish JSON did this...


    http://www.mongodb.org/display/DOCS/BSON
Wednesday, October 28, 2009
Document Storage (BSON)                            B is for Binary

                         { author: 'joe',
                              created: Date('03-28-2009'),
                              title: 'Yet another blog post',
                              text: 'Here is the text...',
                              tags: [ 'example', 'joe' ],
                              comments: [ { author: 'jim', comment: 'I disagree' },
                                          { author: 'nancy', comment: 'Good post' }
                              ]
                         }


                  Sure wish JSON did this...


    http://www.mongodb.org/display/DOCS/BSON
Wednesday, October 28, 2009
That looks like JSON




Wednesday, October 28, 2009
So does this




                              jason.to_json
Wednesday, October 28, 2009
Where's the Ruby?




Wednesday, October 28, 2009
Querying
               db.collection.find({'first_name': 'John'}) # finds all Johns

               db.collection.find({'first_name': /^wynn/i}) # regex

               db.collection.find_first({'_id':1}) # finds first with _id of 1

               db.collection.find({'age': {'$gte': 21}}) # finds possible drinkers

               db.collection.find({'author.first_name':'John'}) # subdocument

               db.collection.find({$where:'this.age >= 6 && this.age <= 18'})




Wednesday, October 28, 2009
More
               Querying
               $in, $nin, $all, $ne, $gt, $gte, $lt, $lte, $size, $where

               :fields (like :select in active record)

               :limit, :offset for pagination

               :sort ascending or descending [['foo', 1], ['bar', -1]]

               count and group (uses map/reduce)

               db.collection.mapReduce(mapfunction,reducefunction[,options]);




Wednesday, October 28, 2009
10 Gen projects on the hub
                   ★ mongo-ruby-driver http://github.com/mongodb/mongo-ruby-
                     driver
                   ★ mongorecord http://github.com/mongodb/mongo-activerecord-
                     ruby




Wednesday, October 28, 2009
MongoMapper               from @jnunemaker

                   ★ Mongo is not MySQL
                   ★ DSL for modeling domain should also teach you Mongo
                   ★ It sounded fun
                   ★ Just released version 0.5.6




Wednesday, October 28, 2009
MongoMapper               from @jnunemaker

                   ★ Mongo is not MySQL
                   ★ DSL for modeling domain should also teach you Mongo
                   ★ It sounded fun
                   ★ Just released version 0.5.6



                       I voted for "Nunemapper"


Wednesday, October 28, 2009
Features
         ★ Typecasting
         ★ Callbacks (ActiveSupport Callbacks)
         ★ Validations
         ★ Connection and database can differ per document
         ★ Create and Update with single or multiple
         ★ Delete and Destroy and _all counterparts
                                                  Be careful. Ordering can be tricky.
         ★ Find: id, ids, :all, : rst, :last
         ★ Associations


Wednesday, October 28, 2009
Example
              class User
                include MongoMapper::Document
                key :name, String, :required => true, :length => 5..100
                key :email, String, :required => true, :index => true
                key :age, Integer, :numeric => true
                key :active, Boolean, :default => true

                one :address
                many :articles
              end
                                           Included as module, not subclassed
                                           (this may change soon).
              class Address
                include MongoMapper::Document
                key :street, String
                key :city, String
                key :state, String, :length => 2
                key :zip, Integer, :numeric => true, :length => 5
              end

Wednesday, October 28, 2009
MongoDB fun
                   ★ Capped collections (think memcache, actually used for replication)
                   ★ Upserts db.collection.update({'_id':1},          {'$inc':
                         {'views':1}})

                   ★ Multikeys (think tagging and full text search)
                   ★ GridFS and auto-sharding




Wednesday, October 28, 2009
So, is it ready for Prime Time?
                   ★ Disqus
                   ★ SourceForge
                   ★ TweetCongress, GovTwit -- Floxee.com
                   ★ TweetSaver.com
                   ★ Mozilla Ubiquity Herd


                                   Ask these folks!



Wednesday, October 28, 2009
Lessons learned in production                         the fine print

                   ★ The laws of computing are still in effect
                   ★ Indexes are important no matter what the salesman told ya about
                     performance
                   ★ Data modeling. Deep or Wide?     The answer is yes!


                   ★ MongoDB and MongoMapper are in active development
                                    Very responsive yet very volatile changes!




Wednesday, October 28, 2009
How can you help?
                   ★ We need an awesome admin GUI
                   ★ Port some plugins (might get easier with ActiveModel support
                     coming soon)
                   ★ Build something cool




Wednesday, October 28, 2009
Resources              an d thanks for having me!

                 http://mongodb.org
                 http://www.10gen.com     the very cool company behind MongoDB

                 http://groups.google.com/group/mongomapper
                 http://groups.google.com/group/mongodb-user
                 http://squeejee.com




                               Questions? I'm @pengwynn on Twitter

                                 http://wynnnetherland.com

                                                    the very new blog

Wednesday, October 28, 2009

Más contenido relacionado

La actualidad más candente

Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Steven Francia
 
MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012Steven Francia
 
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopAhmedabadJavaMeetup
 
An introduction to CouchDB
An introduction to CouchDBAn introduction to CouchDB
An introduction to CouchDBDavid Coallier
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
Intro to Neo4j presentation
Intro to Neo4j presentationIntro to Neo4j presentation
Intro to Neo4j presentationjexp
 
PgREST: Node.js in the Database
PgREST: Node.js in the DatabasePgREST: Node.js in the Database
PgREST: Node.js in the DatabaseAudrey Tang
 
Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DBMihail Mateev
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialSteven Francia
 
Graph Databases & OrientDB
Graph Databases & OrientDBGraph Databases & OrientDB
Graph Databases & OrientDBArpit Poladia
 
Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)
Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)
Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)Matthew Lease
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHPBradley Holt
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJustin Smestad
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 

La actualidad más candente (20)

Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013
 
MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012
 
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and Workshop
 
An introduction to CouchDB
An introduction to CouchDBAn introduction to CouchDB
An introduction to CouchDB
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
MongoDB for Genealogy
MongoDB for GenealogyMongoDB for Genealogy
MongoDB for Genealogy
 
Intro to Neo4j presentation
Intro to Neo4j presentationIntro to Neo4j presentation
Intro to Neo4j presentation
 
PgREST: Node.js in the Database
PgREST: Node.js in the DatabasePgREST: Node.js in the Database
PgREST: Node.js in the Database
 
Dealing with Azure Cosmos DB
Dealing with Azure Cosmos DBDealing with Azure Cosmos DB
Dealing with Azure Cosmos DB
 
Catmandu / LibreCat Project
Catmandu / LibreCat ProjectCatmandu / LibreCat Project
Catmandu / LibreCat Project
 
Catmandu Librecat
Catmandu LibrecatCatmandu Librecat
Catmandu Librecat
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
Apache pig
Apache pigApache pig
Apache pig
 
No sql way_in_pg
No sql way_in_pgNo sql way_in_pg
No sql way_in_pg
 
Graph Databases & OrientDB
Graph Databases & OrientDBGraph Databases & OrientDB
Graph Databases & OrientDB
 
Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)
Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)
Lecture 4: Data-Intensive Computing for Text Analysis (Fall 2011)
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHP
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 

Destacado

Your government is Mashed UP!
Your government is Mashed UP!Your government is Mashed UP!
Your government is Mashed UP!Wynn Netherland
 
Accelerated Native Mobile Development with the Ti gem
Accelerated Native Mobile Development with the Ti gemAccelerated Native Mobile Development with the Ti gem
Accelerated Native Mobile Development with the Ti gemWynn Netherland
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperWynn Netherland
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3 Wynn Netherland
 
America, your congress is Mashed UP!
America, your congress is Mashed UP!America, your congress is Mashed UP!
America, your congress is Mashed UP!Wynn Netherland
 
Helping mobile operators address revenue cannibalisation from OTT communicati...
Helping mobile operators address revenue cannibalisation from OTT communicati...Helping mobile operators address revenue cannibalisation from OTT communicati...
Helping mobile operators address revenue cannibalisation from OTT communicati...Mark Watts - Jones
 

Destacado (8)

Your government is Mashed UP!
Your government is Mashed UP!Your government is Mashed UP!
Your government is Mashed UP!
 
Accelerated Native Mobile Development with the Ti gem
Accelerated Native Mobile Development with the Ti gemAccelerated Native Mobile Development with the Ti gem
Accelerated Native Mobile Development with the Ti gem
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
 
America, your congress is Mashed UP!
America, your congress is Mashed UP!America, your congress is Mashed UP!
America, your congress is Mashed UP!
 
Helping mobile operators address revenue cannibalisation from OTT communicati...
Helping mobile operators address revenue cannibalisation from OTT communicati...Helping mobile operators address revenue cannibalisation from OTT communicati...
Helping mobile operators address revenue cannibalisation from OTT communicati...
 

Similar a Hands on with Ruby & MongoDB

2011 05-12 nosql-progressive.net
2011 05-12 nosql-progressive.net2011 05-12 nosql-progressive.net
2011 05-12 nosql-progressive.netMårten Gustafson
 
HPTS 2011: The NoSQL Ecosystem
HPTS 2011: The NoSQL EcosystemHPTS 2011: The NoSQL Ecosystem
HPTS 2011: The NoSQL EcosystemAdam Marcus
 
The NoSQL Ecosystem
The NoSQL Ecosystem The NoSQL Ecosystem
The NoSQL Ecosystem yarapavan
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02sagaroceanic11
 
A rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkitsA rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkitsBelighted
 
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...cwensel
 
Spring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataSpring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataRoger Xia
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and HowBigBlueHat
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by AccidentGleicon Moraes
 
Implementation of nosql for robotics
Implementation of nosql for roboticsImplementation of nosql for robotics
Implementation of nosql for roboticsJoão Gabriel Lima
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Espen Brækken
 
第17回Cassandra勉強会: MyCassandra
第17回Cassandra勉強会: MyCassandra第17回Cassandra勉強会: MyCassandra
第17回Cassandra勉強会: MyCassandraShun Nakamura
 
Explore the Cosmos (DB) with .NET Core 2.0
Explore the Cosmos (DB) with .NET Core 2.0Explore the Cosmos (DB) with .NET Core 2.0
Explore the Cosmos (DB) with .NET Core 2.0Jeremy Likness
 
DynamoDB Gluecon 2012
DynamoDB Gluecon 2012DynamoDB Gluecon 2012
DynamoDB Gluecon 2012Appirio
 
Gluecon 2012 - DynamoDB
Gluecon 2012 - DynamoDBGluecon 2012 - DynamoDB
Gluecon 2012 - DynamoDBJeff Douglas
 

Similar a Hands on with Ruby & MongoDB (20)

2011 05-12 nosql-progressive.net
2011 05-12 nosql-progressive.net2011 05-12 nosql-progressive.net
2011 05-12 nosql-progressive.net
 
No Sql
No SqlNo Sql
No Sql
 
Developing Distributed Semantic Systems
Developing Distributed Semantic SystemsDeveloping Distributed Semantic Systems
Developing Distributed Semantic Systems
 
HPTS 2011: The NoSQL Ecosystem
HPTS 2011: The NoSQL EcosystemHPTS 2011: The NoSQL Ecosystem
HPTS 2011: The NoSQL Ecosystem
 
The NoSQL Ecosystem
The NoSQL Ecosystem The NoSQL Ecosystem
The NoSQL Ecosystem
 
Nosql seminar
Nosql seminarNosql seminar
Nosql seminar
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02
 
A rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkitsA rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkits
 
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
 
Spring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataSpring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_data
 
NoSQL
NoSQLNoSQL
NoSQL
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and How
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by Accident
 
Implementation of nosql for robotics
Implementation of nosql for roboticsImplementation of nosql for robotics
Implementation of nosql for robotics
 
Everyday - mongodb
Everyday - mongodbEveryday - mongodb
Everyday - mongodb
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
第17回Cassandra勉強会: MyCassandra
第17回Cassandra勉強会: MyCassandra第17回Cassandra勉強会: MyCassandra
第17回Cassandra勉強会: MyCassandra
 
Explore the Cosmos (DB) with .NET Core 2.0
Explore the Cosmos (DB) with .NET Core 2.0Explore the Cosmos (DB) with .NET Core 2.0
Explore the Cosmos (DB) with .NET Core 2.0
 
DynamoDB Gluecon 2012
DynamoDB Gluecon 2012DynamoDB Gluecon 2012
DynamoDB Gluecon 2012
 
Gluecon 2012 - DynamoDB
Gluecon 2012 - DynamoDBGluecon 2012 - DynamoDB
Gluecon 2012 - DynamoDB
 

Último

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Último (20)

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Hands on with Ruby & MongoDB

  • 1. Ruby & ^ Hands on with MongoDB Austin on Rails October 27, 2009 WYNNNETHERLAND Wednesday, October 28, 2009
  • 3. x No SQL? x Wednesday, October 28, 2009
  • 4. When does NOSQL make sense? ★ Your data is stored and retrieved mainly by primary key, without complex joins. ★ You have a non-trivial amount of data, and the thought of managing lots of RDBMS shards and replication failure scenarios gives you the fear. http://www.metabrew.com/article/anti-rdbms-a-list-of-distributed-key-value-stores/ Wednesday, October 28, 2009
  • 5. Key value stores Project Voldemort me ver y cool Ringo Scalaris So space Kai ojects in this Dynomite MemcacheDB pr ThruDB CouchDB Cassandra HBase Hypertable Redis Tokyo Cabinet/Tyrant http://www.metabrew.com/article/anti-rdbms-a-list-of-distributed-key-value-stores/ Wednesday, October 28, 2009
  • 6. Tokyo Cabinet: Popular with Rubyists, Big in Japan Wednesday, October 28, 2009
  • 7. Tokyo Cabinet: Popular with Rubyists, Big in Japan ★ Lightning fast ★ Works best for at objects ★ Tokyo Tyrant for network access http://www.igvita.com/2009/02/13/tokyo-cabinet-beyond-key-value-store/ Wednesday, October 28, 2009
  • 10. CouchDB Apache CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. http://couchdb.apache.org/ Wednesday, October 28, 2009
  • 11. Erlang + Javascript Wednesday, October 28, 2009
  • 12. Map + reduce Wednesday, October 28, 2009
  • 14. Plenty o’ Ruby to go around Wednesday, October 28, 2009
  • 15. Ruby libraries for CouchDB CouchRest Basic model om t he RelaxDB Fr ils talk on Ra CouchPotato CouchFoo A ustin ActiveCouch http://www.slideshare.net/brianthecoder/couchdb Wednesday, October 28, 2009
  • 16. Document stores: a lmost* Throw out everything you learned about DB design * more on this later Wednesday, October 28, 2009
  • 17. SQL CouchDB Prede ned, explicit schema Dynamic, implicit schema Collection of named documents with varying Uniform tables of data structure Normalized. Objects spread across tables. Denormalized. Docs usually self contained. Data Duplication reduced. often duplicated. Must know schema to read/write a complete Must know only document name object Dynamic queries of static schemas Static queries of dynamic schemas http://damienkatz.net/files/What is CouchDB.pdf http://damienkatz.net/files/What is CouchDB.pdf Wednesday, October 28, 2009
  • 18. SQL CouchDB Prede ned, explicit schema Dynamic, implicit schema Collection of named documents with varying Uniform tables of data structure Normalized. Objects spread across tables. Duplication reduced. TheDenormalized. Docs usually selfdetails devil'soften duplicated.contained. Data in the Must know schema to read/write a complete Must know only document name object Dynamic queries of static schemas Static queries of dynamic schemas http://damienkatz.net/files/What is CouchDB.pdf http://damienkatz.net/files/What is CouchDB.pdf Wednesday, October 28, 2009
  • 20. because this is BIG Wednesday, October 28, 2009
  • 22. Runs like Hayes. Hits like Mays. Wednesday, October 28, 2009
  • 23. MongoDB x Wednesday, October 28, 2009
  • 24. Let's just skip to here already! x Wednesday, October 28, 2009
  • 25. Introducing ★ Built For Speedcan be very fast ★ Dynamic Queries and Indexes ★ Replication and Failover ★ Sharding ★ Map / Reduce Wednesday, October 28, 2009
  • 26. MongoDB is great for ★ Websites ★ Caching ★ High volume, low value ★ High scalability stash the hash ★ Storage of program objects and JSON Wednesday, October 28, 2009
  • 27. Not as great for ★ Highly transactional ★ Ad-hoc business intelligence ★ Problems requiring SQL Wednesday, October 28, 2009
  • 28. Installation ★ mkdir -p /data/db ★ download pre-built for OSX and unzip to /usr/local/ ★ cp -R /usr/local/pathtomongo/bin /usr/local/bin Ruby driver for MongoDB ★ sudo gem install mongo Native C ★ sudo gem install mongo_ext extensions ( go turbo! ) ★ sudo gem install mongo_mapper Wednesday, October 28, 2009
  • 29. what's in the box? Contents of mongo/bin ★ mongod - The MongoDB server ★ mongo - the JavaScript interactive shell ★ mongoexport - export data as JSON or csv ★ mongoimport - As advertised was? ★ mongodump - Like mysqldump why? What did you think it ★ mongorestore - Restore from mongodump les ★ mongos - Auto-sharding module (getting better with every build) Wednesday, October 28, 2009
  • 30. Some new terms Wednesday, October 28, 2009
  • 31. When I say database Wednesday, October 28, 2009
  • 32. When I say think database database Wednesday, October 28, 2009
  • 33. When I say think database database Well that one isn't new... Wednesday, October 28, 2009
  • 34. Databases in MongoDB ★ Made up of multiple collections ★ Are created on-the- y when rst referenced Wednesday, October 28, 2009
  • 35. When I say collection Wednesday, October 28, 2009
  • 36. When I say think collection table Wednesday, October 28, 2009
  • 37. Collections in MongoDB ★ Schema-less but typed! ★ For grouping documents into smaller query sets (speed) ★ Indexable by one or more key ★ Are created on-the- y when rst referenced ★ Capped collections: Fixed size, older records dropped after limit reached Wednesday, October 28, 2009
  • 38. When I say document Wednesday, October 28, 2009
  • 39. When I say think document record or row Wednesday, October 28, 2009
  • 40. Document ★ Stored in a collection ★ Can have _id key that works like primary keys in MySQL ★ Supports relationships: subdocument or db reference Wednesday, October 28, 2009
  • 41. Document Storage (BSON) { author: 'joe', created: Date('03-28-2009'), title: 'Yet another blog post', text: 'Here is the text...', tags: [ 'example', 'joe' ], comments: [ { author: 'jim', comment: 'I disagree' }, { author: 'nancy', comment: 'Good post' } ] } http://www.mongodb.org/display/DOCS/BSON Wednesday, October 28, 2009
  • 42. Document Storage (BSON) { author: 'joe', created: Date('03-28-2009'), title: 'Yet another blog post', text: 'Here is the text...', tags: [ 'example', 'joe' ], comments: [ { author: 'jim', comment: 'I disagree' }, { author: 'nancy', comment: 'Good post' } ] } Sure wish JSON did this... http://www.mongodb.org/display/DOCS/BSON Wednesday, October 28, 2009
  • 43. Document Storage (BSON) B is for Binary { author: 'joe', created: Date('03-28-2009'), title: 'Yet another blog post', text: 'Here is the text...', tags: [ 'example', 'joe' ], comments: [ { author: 'jim', comment: 'I disagree' }, { author: 'nancy', comment: 'Good post' } ] } Sure wish JSON did this... http://www.mongodb.org/display/DOCS/BSON Wednesday, October 28, 2009
  • 44. That looks like JSON Wednesday, October 28, 2009
  • 45. So does this jason.to_json Wednesday, October 28, 2009
  • 46. Where's the Ruby? Wednesday, October 28, 2009
  • 47. Querying db.collection.find({'first_name': 'John'}) # finds all Johns db.collection.find({'first_name': /^wynn/i}) # regex db.collection.find_first({'_id':1}) # finds first with _id of 1 db.collection.find({'age': {'$gte': 21}}) # finds possible drinkers db.collection.find({'author.first_name':'John'}) # subdocument db.collection.find({$where:'this.age >= 6 && this.age <= 18'}) Wednesday, October 28, 2009
  • 48. More Querying $in, $nin, $all, $ne, $gt, $gte, $lt, $lte, $size, $where :fields (like :select in active record) :limit, :offset for pagination :sort ascending or descending [['foo', 1], ['bar', -1]] count and group (uses map/reduce) db.collection.mapReduce(mapfunction,reducefunction[,options]); Wednesday, October 28, 2009
  • 49. 10 Gen projects on the hub ★ mongo-ruby-driver http://github.com/mongodb/mongo-ruby- driver ★ mongorecord http://github.com/mongodb/mongo-activerecord- ruby Wednesday, October 28, 2009
  • 50. MongoMapper from @jnunemaker ★ Mongo is not MySQL ★ DSL for modeling domain should also teach you Mongo ★ It sounded fun ★ Just released version 0.5.6 Wednesday, October 28, 2009
  • 51. MongoMapper from @jnunemaker ★ Mongo is not MySQL ★ DSL for modeling domain should also teach you Mongo ★ It sounded fun ★ Just released version 0.5.6 I voted for "Nunemapper" Wednesday, October 28, 2009
  • 52. Features ★ Typecasting ★ Callbacks (ActiveSupport Callbacks) ★ Validations ★ Connection and database can differ per document ★ Create and Update with single or multiple ★ Delete and Destroy and _all counterparts Be careful. Ordering can be tricky. ★ Find: id, ids, :all, : rst, :last ★ Associations Wednesday, October 28, 2009
  • 53. Example class User include MongoMapper::Document key :name, String, :required => true, :length => 5..100 key :email, String, :required => true, :index => true key :age, Integer, :numeric => true key :active, Boolean, :default => true one :address many :articles end Included as module, not subclassed (this may change soon). class Address include MongoMapper::Document key :street, String key :city, String key :state, String, :length => 2 key :zip, Integer, :numeric => true, :length => 5 end Wednesday, October 28, 2009
  • 54. MongoDB fun ★ Capped collections (think memcache, actually used for replication) ★ Upserts db.collection.update({'_id':1}, {'$inc': {'views':1}}) ★ Multikeys (think tagging and full text search) ★ GridFS and auto-sharding Wednesday, October 28, 2009
  • 55. So, is it ready for Prime Time? ★ Disqus ★ SourceForge ★ TweetCongress, GovTwit -- Floxee.com ★ TweetSaver.com ★ Mozilla Ubiquity Herd Ask these folks! Wednesday, October 28, 2009
  • 56. Lessons learned in production the fine print ★ The laws of computing are still in effect ★ Indexes are important no matter what the salesman told ya about performance ★ Data modeling. Deep or Wide? The answer is yes! ★ MongoDB and MongoMapper are in active development Very responsive yet very volatile changes! Wednesday, October 28, 2009
  • 57. How can you help? ★ We need an awesome admin GUI ★ Port some plugins (might get easier with ActiveModel support coming soon) ★ Build something cool Wednesday, October 28, 2009
  • 58. Resources an d thanks for having me! http://mongodb.org http://www.10gen.com the very cool company behind MongoDB http://groups.google.com/group/mongomapper http://groups.google.com/group/mongodb-user http://squeejee.com Questions? I'm @pengwynn on Twitter http://wynnnetherland.com the very new blog Wednesday, October 28, 2009