• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Mongodb Indyrb
 

Mongodb Indyrb

on

  • 4,905 views

Presentation for Indianapolis, IN Ruby Group.

Presentation for Indianapolis, IN Ruby Group.

Statistics

Views

Total Views
4,905
Views on SlideShare
3,728
Embed Views
1,177

Actions

Likes
9
Downloads
50
Comments
0

7 Embeds 1,177

http://railstips.org 1151
http://www.railstips.org 12
http://static.slidesharecdn.com 7
http://www.slideshare.net 3
http://feeds.feedburner.com 2
http://protopage.com 1
http://bgror.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • find always returns a cursor that you can keep iterating through

Mongodb Indyrb Mongodb Indyrb Presentation Transcript

  • WARNING!!! When I get excited, I talk fast. Feel free to remind me to slow down.
  • FEEDBACK @jnunemaker and @mongodb
  • WHY? WHAT? HOW?
  • WHY?
  • • Scaling, schmaling • Hammer/Nail • Example (Harmony http://harmonyapp.com)
  • WHAT?
  • INTRO • Built For Speed • Document/Collection Oriented • Dynamic Queries and Indexes • Replication and Failover
  • GREAT FOR • Websites • Caching • High volume, low value • High scalability • Storage of program objects and json
  • NOT AS GREAT FOR • Highly transactional • Ad-hoc business intelligence • Problems requiring SQL
  • INSTALLATION • mkdir -p /data/db • download, unzip, mongod run • http://video.railstips.org/mongomapper-demo/
  • DATABASE • same concept as mysql • made up of collections
  • COLLECTION • Think table, but with no schema • For grouping documents into smaller query sets (speed) • Eachtop level entity in your app would have its own collection (users, articles, etc.) • Indexable by one or more key
  • DOCUMENT • Stored in a collection, think record or row • Can have _id key that works like primary keys in MySQL • Three options for relationships: embedded document, foreign keys, or db reference
  • QUERYING • db.collection.find({‘first_name’: ‘John’}) # finds all Johns • db.collection.find({‘first_name’: /^J/}) # regex • db.collection.find_first({‘_id’:1}) # finds first with _id of 1 • db.collection.find({‘age’: {‘$gt’: 21}}) # finds possible drinkers • db.collection.find({‘author.first_name’:‘John’}) # subdocument • db.collection.find({$where:‘this.age >= 6 && this.age <= 18’})
  • 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)
  • HOW?
  • HOW DO YOU USE IT WITH RUBY • mongo-ruby-driver http://github.com/mongodb/mongo-ruby- driver • activerecord adapter http://github.com/mongodb/ activerecord-mongo-adapter • mongorecord http://github.com/mongodb/mongo- activerecord-ruby
  • NUNEMAPPER (MONGOMAPPER) • Mongo is not MySQL • DSL for modeling domain should also teach you Mongo • It sounded fun • Major appreciation for ORM’s
  • FEATURES • Typecasting • Create and Update with single or multiple • Callbacks(ActiveSupport Callbacks) • Delete and Destroy and _all counterparts • Validations (using my fork of validatable) • Find: id, ids, :all, :first, :last • Connection and database • Associations can differ per document
  • 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 key :address, Address many :articles end class Address include MongoMapper::EmbeddedDocument key :street, String key :city, String key :state, String, :length => 2 key :zip, Integer, :numeric => true, :length => 5 end
  • RANDOM AWESOMENESS • 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
  • LINKS • http://railstips.org/2009/6/3/what-if-a-key-value-store-mated-with-a-relational-database-system • http://railstips.org/2009/6/27/mongomapper-the-rad-mongo-wrapper • http://railstips.org/2009/7/23/getting-started-with-mongomapper-and-rails • http://locomotivation.squeejee.com/post/117119353/mongodb-ruby-friendly-document-storage- that-doesnt-rhyme • http://mongodb.com/ • http://10gen.com
  • John Nunemaker http://orderedlist.com http://railstips.org