121
PRACTICAL PROJECTS WITH Saturday, July 17, 2010

Practical Ruby Projects with MongoDB - Ruby Midwest

Embed Size (px)

Citation preview

Page 1: Practical Ruby Projects with MongoDB - Ruby Midwest

PRACTICAL

PROJECTS WITH

Saturday, July 17, 2010

Page 2: Practical Ruby Projects with MongoDB - Ruby Midwest

WHO AM I?

Alex SharpLead Developer at OptimisDev

@ajsharp (on the twitters)

alexjsharp.com (on the ‘tubes)

github.com/ajsharp (on the ‘hubs)

Saturday, July 17, 2010

Page 3: Practical Ruby Projects with MongoDB - Ruby Midwest

MAJOR POINTS

• Brief intro to MongoDB

• Practical Projects

• Making the case for Mongo (time permitting)

Saturday, July 17, 2010

Page 4: Practical Ruby Projects with MongoDB - Ruby Midwest

BRIEF INTRO

Saturday, July 17, 2010

Page 5: Practical Ruby Projects with MongoDB - Ruby Midwest

WHAT IS MONGODB?

mongodb is a high-performance, schema-less, document-oriented database

Saturday, July 17, 2010

Page 6: Practical Ruby Projects with MongoDB - Ruby Midwest

STRENGTHS

Saturday, July 17, 2010

Page 7: Practical Ruby Projects with MongoDB - Ruby Midwest

SCHEMA-LESS

Saturday, July 17, 2010

Page 8: Practical Ruby Projects with MongoDB - Ruby Midwest

SCHEMA-LESS• Great for rapid, iterative, agile development

Saturday, July 17, 2010

Page 9: Practical Ruby Projects with MongoDB - Ruby Midwest

SCHEMA-LESS• Great for rapid, iterative, agile development

• Makes things possible that in an rdbms are either

a. impossibly hard

b. virtually impossible

c. way harder than they should be

Saturday, July 17, 2010

Page 10: Practical Ruby Projects with MongoDB - Ruby Midwest

DOCUMENT-ORIENTED

Saturday, July 17, 2010

Page 11: Practical Ruby Projects with MongoDB - Ruby Midwest

DOCUMENT-ORIENTED

• Mongo stores documents, not rows

• documents are stored as binary json

Saturday, July 17, 2010

Page 12: Practical Ruby Projects with MongoDB - Ruby Midwest

DOCUMENT-ORIENTED

• Mongo stores documents, not rows

• documents are stored as binary json

• Allows for a rich query syntax

Saturday, July 17, 2010

Page 13: Practical Ruby Projects with MongoDB - Ruby Midwest

DOCUMENT-ORIENTED

• Mongo stores documents, not rows

• documents are stored as binary json

• Allows for a rich query syntax

• Embedded documents eliminate many modeling headaches

Saturday, July 17, 2010

Page 14: Practical Ruby Projects with MongoDB - Ruby Midwest

BIG DATA

Saturday, July 17, 2010

Page 15: Practical Ruby Projects with MongoDB - Ruby Midwest

BIG DATA

• Built to scale horizontally into the cloudz

Saturday, July 17, 2010

Page 16: Practical Ruby Projects with MongoDB - Ruby Midwest

BIG DATA

• Built to scale horizontally into the cloudz

• Auto-sharding

• set a shard-key, a cluster of nodes, go

• still in alpha, but production-ready soon

Saturday, July 17, 2010

Page 17: Practical Ruby Projects with MongoDB - Ruby Midwest

FAST WRITES

Saturday, July 17, 2010

Page 18: Practical Ruby Projects with MongoDB - Ruby Midwest

FAST WRITES

• Mongo writes are “fire-and-forget”

• you can get a response with getLastError()

Saturday, July 17, 2010

Page 19: Practical Ruby Projects with MongoDB - Ruby Midwest

FAST WRITES

• Mongo writes are “fire-and-forget”

• you can get a response with getLastError()

• In-place updates

Saturday, July 17, 2010

Page 20: Practical Ruby Projects with MongoDB - Ruby Midwest

FAST WRITES

• Mongo writes are “fire-and-forget”

• you can get a response with getLastError()

• In-place updates

• Lot’s of db commands for fast updates

Saturday, July 17, 2010

Page 21: Practical Ruby Projects with MongoDB - Ruby Midwest

AGGREGATION

Map/reduce for aggregation

Saturday, July 17, 2010

Page 22: Practical Ruby Projects with MongoDB - Ruby Midwest

READS FAST TOO

Optimize reads with indexes, just like an rdbms

Saturday, July 17, 2010

Page 23: Practical Ruby Projects with MongoDB - Ruby Midwest

WEAKNESSES

Saturday, July 17, 2010

Page 24: Practical Ruby Projects with MongoDB - Ruby Midwest

JOINS

nope.

Saturday, July 17, 2010

Page 25: Practical Ruby Projects with MongoDB - Ruby Midwest

MULTI-DOCUMENTTRANSACTIONS

no-sir-ee.

Saturday, July 17, 2010

Page 26: Practical Ruby Projects with MongoDB - Ruby Midwest

RELATIONAL INTEGRITY

not a chance.

Saturday, July 17, 2010

Page 27: Practical Ruby Projects with MongoDB - Ruby Midwest

PRACTICAL PROJECTS

Saturday, July 17, 2010

Page 28: Practical Ruby Projects with MongoDB - Ruby Midwest

1. Accounting Application

2. Capped Collection Logging

3. Blogging app

4. Reporting app

Saturday, July 17, 2010

Page 29: Practical Ruby Projects with MongoDB - Ruby Midwest

GENERAL LEDGER ACCOUNTING APPLICATION

Saturday, July 17, 2010

Page 30: Practical Ruby Projects with MongoDB - Ruby Midwest

THE OBJECT MODELledger

transactions

entries

*

*

Saturday, July 17, 2010

Page 31: Practical Ruby Projects with MongoDB - Ruby Midwest

THE OBJECT MODEL

# Credits Debits

1 { :account => “Cash”, :amount => 100.00 }

{ :account => “Notes Pay.”, :amount => 100.00 }

2 { :account => “A/R”, :amount => 25.00 }

{ :account => “Gross Revenue”, :amount => 25.00 }

Ledger Entries

{

Line item {

Line item

Saturday, July 17, 2010

Page 32: Practical Ruby Projects with MongoDB - Ruby Midwest

THE OBJECT MODEL

Saturday, July 17, 2010

Page 33: Practical Ruby Projects with MongoDB - Ruby Midwest

THE OBJECT MODEL

• Each ledger line item belongs to a ledger

Saturday, July 17, 2010

Page 34: Practical Ruby Projects with MongoDB - Ruby Midwest

THE OBJECT MODEL

• Each ledger line item belongs to a ledger

• Each ledger line item has two ledger entries

• must have at least one credit and one debit

• credits and debits must balance

Saturday, July 17, 2010

Page 35: Practical Ruby Projects with MongoDB - Ruby Midwest

THE OBJECT MODEL

• Each ledger line item belongs to a ledger

• Each ledger line item has two ledger entries

• must have at least one credit and one debit

• credits and debits must balance

• These objects must be transactional

Saturday, July 17, 2010

Page 36: Practical Ruby Projects with MongoDB - Ruby Midwest

@debit = Entry.new(:account => 'Cash', :amount => 100.00, :type => 'credit')

@credit = Entry.new(:account => 'Notes Pay.', :amount => 100.00, :type => 'debit')

@line_item = LineItem.new :ledger_id => 1, :entries => [@debit, @credit]

SQL-BASED OBJECT MODEL

Saturday, July 17, 2010

Page 37: Practical Ruby Projects with MongoDB - Ruby Midwest

@debit = Entry.new(:account => 'Cash', :amount => 100.00, :type => 'credit')

@credit = Entry.new(:account => 'Notes Pay.', :amount => 100.00, :type => 'debit')

@line_item = LineItem.new :ledger_id => 1, :entries => [@debit, @credit]

In a SQL schema, we need a database transaction to ensure multi-row atomicity

SQL-BASED OBJECT MODEL

Saturday, July 17, 2010

Page 38: Practical Ruby Projects with MongoDB - Ruby Midwest

@debit = Entry.new(:account => 'Cash', :amount => 100.00, :type => 'credit')

@credit = Entry.new(:account => 'Notes Pay.', :amount => 100.00, :type => 'debit')

@line_item = LineItem.new :ledger_id => 1, :entries => [@debit, @credit]

Remember: we have to create 3 new records in the database here

SQL-BASED OBJECT MODEL

Saturday, July 17, 2010

Page 39: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGO-FIED MODELING@line_item = LineItem.new(:ledger_id => 1, :entries => [ {:account => 'Cash', :type => 'debit', :amount => 100}, {:account => 'Notes pay.', :type => 'debit', :amount => 100} ])

Saturday, July 17, 2010

Page 40: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGO-FIED MODELING

This is the perfect case for embedded documents.

@line_item = LineItem.new(:ledger_id => 1, :entries => [ {:account => 'Cash', :type => 'debit', :amount => 100}, {:account => 'Notes pay.', :type => 'debit', :amount => 100} ])

Saturday, July 17, 2010

Page 41: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGO-FIED MODELING

We will never have more than a few entries (usually two)

@line_item = LineItem.new(:ledger_id => 1, :entries => [ {:account => 'Cash', :type => 'debit', :amount => 100}, {:account => 'Notes pay.', :type => 'debit', :amount => 100} ])

Saturday, July 17, 2010

Page 42: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGO-FIED MODELING@line_item = LineItem.new(:ledger_id => 1, :entries => [ {:account => 'Cash', :type => 'debit', :amount => 100}, {:account => 'Notes pay.', :type => 'debit', :amount => 100} ])

Embedded docs are perfect for “contains” many relationships

Saturday, July 17, 2010

Page 43: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGO-FIED MODELING

DB-level transactions no-longer needed.Mongo has single document atomicity.

@line_item = LineItem.new(:ledger_id => 1, :entries => [ {:account => 'Cash', :type => 'debit', :amount => 100}, {:account => 'Notes pay.', :type => 'debit', :amount => 100} ])

Saturday, July 17, 2010

Page 44: Practical Ruby Projects with MongoDB - Ruby Midwest

LESSONS

Saturday, July 17, 2010

Page 45: Practical Ruby Projects with MongoDB - Ruby Midwest

LESSONS

•Simplified, de-normalized data model

•Objects modeled differently in Mongo than SQL

Saturday, July 17, 2010

Page 46: Practical Ruby Projects with MongoDB - Ruby Midwest

LESSONS

•Simplified, de-normalized data model

•Objects modeled differently in Mongo than SQL

•Simpler data model + no transactions = WIN

Saturday, July 17, 2010

Page 47: Practical Ruby Projects with MongoDB - Ruby Midwest

LOGGING WITH CAPPED

COLLECTIONS

Saturday, July 17, 2010

Page 48: Practical Ruby Projects with MongoDB - Ruby Midwest

BASELESS STATISTIC

95% of the time logs are NEVER used.

Saturday, July 17, 2010

Page 49: Practical Ruby Projects with MongoDB - Ruby Midwest

MOST LOGS ARE ONLY USED WHEN SOMETHING GOES

WRONG

Saturday, July 17, 2010

Page 50: Practical Ruby Projects with MongoDB - Ruby Midwest

• Fixed-sized, limited operation, auto age-out collections (kinda like memcached, except persistent)

• Fixed insertion order

• Super fast (faster than normal writes)

• Ideal for logging and caching

CAPPED COLLECTIONS

Saturday, July 17, 2010

Page 51: Practical Ruby Projects with MongoDB - Ruby Midwest

GREAT. WHAT’S THAT MEAN?

We can log additional pieces of arbitrary data effortlessly due to Mongo’s schemaless nature.

Saturday, July 17, 2010

Page 52: Practical Ruby Projects with MongoDB - Ruby Midwest

THIS IS AWESOME

Saturday, July 17, 2010

Page 53: Practical Ruby Projects with MongoDB - Ruby Midwest

QUERY. ANALYZE. PROFIT.

Saturday, July 17, 2010

Page 54: Practical Ruby Projects with MongoDB - Ruby Midwest

ALSO A REALLY HANDY TROUBLESHOOTING TOOL

Saturday, July 17, 2010

Page 55: Practical Ruby Projects with MongoDB - Ruby Midwest

User-reported errors are difficult to diagnose

Saturday, July 17, 2010

Page 56: Practical Ruby Projects with MongoDB - Ruby Midwest

Wouldn’t it be useful to see the complete click-path?

Saturday, July 17, 2010

Page 57: Practical Ruby Projects with MongoDB - Ruby Midwest

BUNYAN

Thin ruby layer around a MongoDB capped collection

http://github.com/ajsharp/bunyan

Saturday, July 17, 2010

Page 58: Practical Ruby Projects with MongoDB - Ruby Midwest

BUNYAN

Still needs a middleware api.

Want to contribute?

http://github.com/ajsharp/bunyan

Saturday, July 17, 2010

Page 59: Practical Ruby Projects with MongoDB - Ruby Midwest

Text

require 'bunyan'

Bunyan::Logger.configure do |c| c.database 'my_bunyan_db' c.collection "#{Rails.env}_bunyan_log" c.size 1073741824 # 1.gigabyteend

Saturday, July 17, 2010

Page 60: Practical Ruby Projects with MongoDB - Ruby Midwest

SINATRA FRONT-END TO BUNYAN

PAPERMILLhttp://github.com/ajsharp/papermill

Saturday, July 17, 2010

Page 61: Practical Ruby Projects with MongoDB - Ruby Midwest

BLOGGING APPLICATION

Saturday, July 17, 2010

Page 62: Practical Ruby Projects with MongoDB - Ruby Midwest

BLOGGING APPLICATION

Much easier to model with Mongo than a relational database

Saturday, July 17, 2010

Page 63: Practical Ruby Projects with MongoDB - Ruby Midwest

A post has an author

BLOGGING APPLICATION

Saturday, July 17, 2010

Page 64: Practical Ruby Projects with MongoDB - Ruby Midwest

A post has an author

A post has many tags

BLOGGING APPLICATION

Saturday, July 17, 2010

Page 65: Practical Ruby Projects with MongoDB - Ruby Midwest

A post has an author

A post has many tags

BLOGGING APPLICATION

A post has many comments

Saturday, July 17, 2010

Page 66: Practical Ruby Projects with MongoDB - Ruby Midwest

A post has an author

A post has many tags

A post has many comments

Instead of JOINing separate tables,we can use embedded documents.

BLOGGING APPLICATION

Saturday, July 17, 2010

Page 67: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGOMAPPER

Saturday, July 17, 2010

Page 68: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGOMAPPER•MongoDB “ORM” developed by John Nunemaker

Saturday, July 17, 2010

Page 69: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGOMAPPER•MongoDB “ORM” developed by John Nunemaker

•Very similar syntax to DataMapper

Saturday, July 17, 2010

Page 70: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGOMAPPER•MongoDB “ORM” developed by John Nunemaker

•Very similar syntax to DataMapper

•Declarative rather than inheritance-based

Saturday, July 17, 2010

Page 71: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGOMAPPER•MongoDB “ORM” developed by John Nunemaker

•Very similar syntax to DataMapper

•Declarative rather than inheritance-based

•Very easy to drop into rails

Saturday, July 17, 2010

Page 72: Practical Ruby Projects with MongoDB - Ruby Midwest

require 'mongo'connection = Mongo::Connection.new.db("#{Rails.env}_app")

class Post include MongoMapper::Document belongs_to :author, :class_name => "User" key :title, String, :reuqired => true key :body, String, :required => true key :author_id, Integer, :required => true key :published_at, Time key :published, Boolean, :default => false key :tags, Array, :default => [] timestamps!end

MONGOMAPPER

Saturday, July 17, 2010

Page 73: Practical Ruby Projects with MongoDB - Ruby Midwest

REPORTING APP

Saturday, July 17, 2010

Page 74: Practical Ruby Projects with MongoDB - Ruby Midwest

Saturday, July 17, 2010

Page 75: Practical Ruby Projects with MongoDB - Ruby Midwest

REPORTING IS HARD• Synchronization

• Data, application API, schema

• Schema synchronization is the hard one

Saturday, July 17, 2010

Page 76: Practical Ruby Projects with MongoDB - Ruby Midwest

WHY MONGO?

• Aggregation support with Mongo’s map/reduce support

• Mongo is good (and getting better) at handling big data sets

• Schemaless is perfect for a flattened data set

Saturday, July 17, 2010

Page 77: Practical Ruby Projects with MongoDB - Ruby Midwest

Transform

Main AppReporting App

RackspaceAmazon EC2

MongoDB Server

MySQL

WAN

Saturday, July 17, 2010

Page 78: Practical Ruby Projects with MongoDB - Ruby Midwest

Reporting App

Amazon EC2

MongoDB Server

GET /reports/some_reportUser requests

Client request

map/reduce

CLIENT REQUESTS

Saturday, July 17, 2010

Page 79: Practical Ruby Projects with MongoDB - Ruby Midwest

TRANFORMATIONData needs to extracted from the the main app, transormed (i.e. flattened) into some other form,

and loaded into the reporting app for aggregation

Saturday, July 17, 2010

Page 80: Practical Ruby Projects with MongoDB - Ruby Midwest

Transform

Main AppReporting App

1. GET /object_dependencies

{ :visit => [ :insurances, :patients ] }

2. read from active record

2. write to mongo

Rackspace Amazon EC2

MongoDB Server

MySQL

TRANSFORMATION

Saturday, July 17, 2010

Page 81: Practical Ruby Projects with MongoDB - Ruby Midwest

MAKING THE CASE

Saturday, July 17, 2010

Page 82: Practical Ruby Projects with MongoDB - Ruby Midwest

THE PROBLEMS OF SQL

Saturday, July 17, 2010

Page 83: Practical Ruby Projects with MongoDB - Ruby Midwest

A BRIEF HISTORY OF SQL

• Developed at IBM in early 1970’s.

• Designed to manipulate and retrieve data stored in relational databases

Saturday, July 17, 2010

Page 84: Practical Ruby Projects with MongoDB - Ruby Midwest

A BRIEF HISTORY OF SQL

• Developed at IBM in early 1970’s.

• Designed to manipulate and retrieve data stored in relational databases

this is a problem

Saturday, July 17, 2010

Page 85: Practical Ruby Projects with MongoDB - Ruby Midwest

WHY??

Saturday, July 17, 2010

Page 86: Practical Ruby Projects with MongoDB - Ruby Midwest

WE DON’T WORK WITH DATA...

Saturday, July 17, 2010

Page 87: Practical Ruby Projects with MongoDB - Ruby Midwest

WE WORK WITH OBJECTS

Saturday, July 17, 2010

Page 88: Practical Ruby Projects with MongoDB - Ruby Midwest

WE DON’T CARE ABOUT

STORING DATA

Saturday, July 17, 2010

Page 89: Practical Ruby Projects with MongoDB - Ruby Midwest

WE CARE ABOUT PERSISTING STATE

Saturday, July 17, 2010

Page 90: Practical Ruby Projects with MongoDB - Ruby Midwest

DATA != OBJECTS

Saturday, July 17, 2010

Page 91: Practical Ruby Projects with MongoDB - Ruby Midwest

THEREFORE...

Saturday, July 17, 2010

Page 92: Practical Ruby Projects with MongoDB - Ruby Midwest

RELATIONAL DBS ARE AN ANTIQUATED TOOL FOR OUR

NEEDS

Saturday, July 17, 2010

Page 93: Practical Ruby Projects with MongoDB - Ruby Midwest

OK, SO WHAT?

SQL schemas are designed for storing and querying data, not persisting objects.

Saturday, July 17, 2010

Page 94: Practical Ruby Projects with MongoDB - Ruby Midwest

To reconcile this mismatch, we have

ORM’s

Saturday, July 17, 2010

Page 95: Practical Ruby Projects with MongoDB - Ruby Midwest

Object Relational Mappers

Saturday, July 17, 2010

Page 96: Practical Ruby Projects with MongoDB - Ruby Midwest

OK, SO WHAT?We need ORMs to bridge the gap (map) between our native Ruby object model and a SQL schema

Saturday, July 17, 2010

Page 97: Practical Ruby Projects with MongoDB - Ruby Midwest

We’re forced to create relationships for data

when what we really want is properties for our objects.

Saturday, July 17, 2010

Page 98: Practical Ruby Projects with MongoDB - Ruby Midwest

THIS IS NOT EFFICIENT

Saturday, July 17, 2010

Page 99: Practical Ruby Projects with MongoDB - Ruby Midwest

@alex = Person.new( :name => "alex", :stalkings => [ Friend.new("Jim"), Friend.new("Bob")])

Saturday, July 17, 2010

Page 100: Practical Ruby Projects with MongoDB - Ruby Midwest

<Person:0x10017d030 @name="alex", @stalkings= [#<Friend:0x10017d0a8 @name="Jim">, #<Friend:0x10017d058 @name="Bob">]>

Native ruby object

Saturday, July 17, 2010

Page 101: Practical Ruby Projects with MongoDB - Ruby Midwest

@alex.to_json{ name: "alex", stalkings: [{ name: "Jim" }, { name: "Bob" }] }

JSON/Mongo Representation

Saturday, July 17, 2010

Page 102: Practical Ruby Projects with MongoDB - Ruby Midwest

SQL Schema Representation

people: - name

stalkings: - name - stalker_id

Saturday, July 17, 2010

Page 103: Practical Ruby Projects with MongoDB - Ruby Midwest

What!?

SQL Schema Representationpeople: - name

stalkings: - name - stalker_id

Saturday, July 17, 2010

Page 104: Practical Ruby Projects with MongoDB - Ruby Midwest

what’s a stalker_id?

SQL Schema Representationpeople: - name

stalkings: - name - stalker_id

Saturday, July 17, 2010

Page 105: Practical Ruby Projects with MongoDB - Ruby Midwest

this is our sql mapping

SQL Schema Representationpeople: - name

stalkings: - name - stalker_id

Saturday, July 17, 2010

Page 106: Practical Ruby Projects with MongoDB - Ruby Midwest

this is the “pointless” join

SQL Schema Representationpeople: - name

stalkings: - name - stalker_id

Saturday, July 17, 2010

Page 107: Practical Ruby Projects with MongoDB - Ruby Midwest

Ruby -> JSON -> SQL

@alex.to_json{ name: "alex", stalkings: [{ name: "Jim" }, { name: "Bob" }] }

<Person:0x10017d030 @name="alex", @stalkings= [#<Friend:0x10017d0a8 @name="Jim">, #<Friend:0x10017d058 @name="Bob">]>

Ruby

JSON

SQL

people: - name

stalkings: - name - stalker_id

Saturday, July 17, 2010

Page 108: Practical Ruby Projects with MongoDB - Ruby Midwest

Ruby -> JSON -> SQL

@alex.to_json{ name: "alex", stalkings: [{ name: "Jim" }, { name: "Bob" }] }

<Person:0x10017d030 @name="alex", @stalkings= [#<Friend:0x10017d0a8 @name="Jim">, #<Friend:0x10017d058 @name="Bob">]>

Ruby

JSON

SQL

people: - name

stalkings: - name - stalker_id

Feels like we’re having to work too hard here

Saturday, July 17, 2010

Page 109: Practical Ruby Projects with MongoDB - Ruby Midwest

You’re probably thinking...

“Listen GUY, SQL isn’t that bad”

Saturday, July 17, 2010

Page 110: Practical Ruby Projects with MongoDB - Ruby Midwest

Maybe.

Saturday, July 17, 2010

Page 111: Practical Ruby Projects with MongoDB - Ruby Midwest

But we can do much, much better.

Saturday, July 17, 2010

Page 112: Practical Ruby Projects with MongoDB - Ruby Midwest

NEEDS FOR A PERSISTENCE LAYER:

Saturday, July 17, 2010

Page 113: Practical Ruby Projects with MongoDB - Ruby Midwest

NEEDS FOR A PERSISTENCE LAYER:

1. To persist the native state of our objects

Saturday, July 17, 2010

Page 114: Practical Ruby Projects with MongoDB - Ruby Midwest

NEEDS FOR A PERSISTENCE LAYER:

1. To persist the native state of our objects

2. Should NOT interfere w/ application development

Saturday, July 17, 2010

Page 115: Practical Ruby Projects with MongoDB - Ruby Midwest

NEEDS FOR A PERSISTENCE LAYER:

1. To persist the native state of our objects

2. Should NOT interfere w/ application development

3. Provides features necessary to build modern web apps

Saturday, July 17, 2010

Page 116: Practical Ruby Projects with MongoDB - Ruby Midwest

NEXT STEPS

Saturday, July 17, 2010

Page 117: Practical Ruby Projects with MongoDB - Ruby Midwest

USING MONGO W/ RUBY

• Ruby mongo driver

• MongoMapper (github.com/jnunemaker/mongomapper)

• MongoID (github.com/durran/mongoid)

• Many other ORM/ODM’s

• mongo-sequel (github.com/jeremyevans/sequel-mongo)

• moneta (github.com/wycats/moneta)

Saturday, July 17, 2010

Page 118: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGOMAPPER• DataMapper-like API

• good for moving from a sql schema to mongo

• easy to drop into rails

• works with rails 3

Saturday, July 17, 2010

Page 119: Practical Ruby Projects with MongoDB - Ruby Midwest

MONGOID• DataMapper-like API

• uses ActiveModel, so familiar validation syntax

• more opinionated embedded docs

• easy to drop into rails

• rails 2 - mongoid 1.x

• rails 3 - mongoid 2.x

Saturday, July 17, 2010

Page 120: Practical Ruby Projects with MongoDB - Ruby Midwest

QUESTIONS?

Saturday, July 17, 2010

Page 121: Practical Ruby Projects with MongoDB - Ruby Midwest

THANKS!

Saturday, July 17, 2010