• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Hands on with Ruby & MongoDB
 

Hands on with Ruby & MongoDB

on

  • 14,382 views

Slides from talk at Austin on Rails on using MongoDB with Ruby.

Slides from talk at Austin on Rails on using MongoDB with Ruby.

Statistics

Views

Total Views
14,382
Views on SlideShare
12,621
Embed Views
1,761

Actions

Likes
35
Downloads
281
Comments
3

44 Embeds 1,761

http://rubyrailsandwindows.blogspot.com 811
http://wynnnetherland.com 376
http://rubyrailsandwindows.blogspot.in 144
http://www.slideshare.net 99
http://rubyrailsandwindows.blogspot.com.br 36
http://rubyrailsandwindows.blogspot.co.uk 32
http://www.rubyrailsandwindows.blogspot.ru 26
http://rubyrailsandwindows.blogspot.de 25
http://rubyrailsandwindows.blogspot.ru 21
http://rubyrailsandwindows.blogspot.fr 18
http://rubyrailsandwindows.blogspot.com.au 15
http://rubyrailsandwindows.blogspot.se 13
http://rubyrailsandwindows.blogspot.jp 13
http://rubyrailsandwindows.blogspot.ca 13
http://rubyrailsandwindows.blogspot.ch 12
http://rubyrailsandwindows.blogspot.com.es 10
http://rubyrailsandwindows.blogspot.it 10
http://rubyrailsandwindows.blogspot.mx 9
http://rubyrailsandwindows.blogspot.com.ar 8
http://rubyrailsandwindows.blogspot.ro 7
http://aulenbac.tumblr.com 6
http://rubyrailsandwindows.blogspot.nl 6
http://rubyrailsandwindows.blogspot.ie 6
http://www.mefeedia.com 5
http://rubyrailsandwindows.blogspot.co.il 5
http://rubyrailsandwindows.blogspot.cz 3
http://rubyrailsandwindows.blogspot.kr 3
http://rubyrailsandwindows.blogspot.pt 3
http://webcache.googleusercontent.com 3
http://sexydev.soup.io 2
http://rubyrailsandwindows.blogspot.no 2
http://rubyrailsandwindows.blogspot.com.tr 2
http://rubyrailsandwindows.blogspot.dk 2
http://rubyrailsandwindows.blogspot.sk 2
http://wynn.dev 2
http://rubyrailsandwindows.blogspot.co.nz 2
http://translate.googleusercontent.com 2
http://rubyrailsandwindows.blogspot.fi 1
http://rubyrailsandwindows.blogspot.gr 1
http://rubyrailsandwindows.blogspot.hk 1
http://rubyrailsandwindows.blogspot.co.at 1
http://rubyrailsandwindows.blogspot.tw 1
http://paper.li 1
http://www.rubyrailsandwindows.blogspot.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

13 of 3 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Write a comment...
    Are you sure you want to
    Your message goes here
    Processing…
  • l like
    Are you sure you want to
    Your message goes here
    Processing…
  • i like this slide style
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Hands on with Ruby & MongoDB Hands on with Ruby & MongoDB Presentation Transcript

    • 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