SlideShare a Scribd company logo
1 of 56
Download to read offline
Building Good Relations
Using MongoDB and a relational database in your apps
Hayes Davis
  @hayesdavis
 CheapTweet.com
If you’ve already got
        an app
You probably already
  have a database
It’s probably relational




                   http://www.mbari.org/ssds/ReferenceDocuments/RDB_ER.gif
It’s probably
gotten a little
     bit big

         http://www.neonlite.ca/archives/images/big%20cat.jpg
Or maybe it’s
gotten huge



                http://www.fahad.com/pics/liger.jpg
And it’s probably
pretty complicated
                 http://www.mazes.org.uk/i/101005m.gif
Or maybe
  really
complicated

              http://tommilsom.com/wp-content/files/france/maze.jpg
Which makes it harder
     to change
                  http://twitter.com/dacort/status/11023722831
But, you’re not
going to throw
  all that out

                  http://blog.makezine.com/284163191_6f09179853_o.jpg
So let’s make NoSQL
and SQL live in harmony




               http://curiousanimals.net/wp-content/uploads/2008/03/cat-and-dog-sleep.jpg
But first...
Do you even need to?
We all want to
play with shiny
   new toys

    http://actionfan.files.wordpress.com/2009/07/voltron_metallic-vinyl-edit.jpg
But sometimes
 that’s not the
   best plan

                  http://www.pwn3d.us/wp-content/uploads/2006/11/voltron_1.jpg
So, give yourself a test
#1
Is my data relational?
#1
Are my data relational?
#2
   Do my data access
patterns lend themselves
   to denormaliation?
#3
Do I expect a lot of
 schema change?
#4
    Can I drop ACID?
(Atomicity, Consistency, Isolation, Durability)
#5
Do I want to support a
     new piece of
    infrastructure?
If you answered yes to
any of these questions...
... at least for parts of
        your app...
... then
 MongoDB
  might be
right for you

                http://www.rankopedia.com/CandidatePix/25781.gif
Where to start...
Utilities and supporting
           tools
Logging & analysis
              http://sbadrinath.files.wordpress.com/2009/03/different26rqcu3.jpg
We built Parrot




           http://filmfanatic.org/reviews/wp-content/uploads/2008/01/anfscd-parrot.png
Isolated
subsystems


             http://themarkvolta.files.wordpress.com/2009/01/lost-map.jpg
Comments might be a
   good choice
           http://www.readwriteweb.com/archives/facebook_wants_to_be_your_one_true_login.php
Getting practical
   (in Rails, at least)
Using MongoMapper
 and ActiveRecord
Getting set up
config/mongodb.yml
development:
  host: 127.0.0.1

test:
  host: 127.0.0.1

production:
  host: mongo-server.local
config/initializers/mongo.rb
# Read in the config info
mongo_cfg = YAML.load(
  IO.read("#{RAILS_ROOT}/config/mongodb.yml")
)[RAILS_ENV]

# Create the connection from mongodb.yml
args = [mongo_cfg['host'],mongo_cfg['port']].compact
MongoMapper.connection =
  Mongo::Connection.new(*conn_args)

# Pick the Mongo database
db_cfg =
  Rails.configuration.database_configuration[RAILS_ENV]
MongoMapper.database =
  mongo_cfg['database'] || db_cfg['database']
Mixing your MM with
      your AR
              http://i.treehugger.com/images/2007/10/24/frankenstein-jj-001.jpg
app/models/
preferences.rb
class Preferences

  include MongoMapper::Document

  key :user_id, Integer

end
apps/models/user.rb
class User < ActiveRecord::Base

  after_save :save_prefs

  def preferences
    @preferences ||= Preferences.find_or_create_by_user_id(id)
  end

  private
    def save_prefs
      @preferences.save if @preferences
    end

end
Usage
# Set any preferences you like
user = User.find_by_login('thatguy')
user.preferences[:foreground] = '#FF0000'
user.preferences[:foo] = 'bar'
user.save

# Later on, you can do this
user = User.find_by_login('thatguy')
user.preferences[:foreground] #returns '#FF0000'
Our general solution
active-expando
 (very, very alpha)
Any attribute, any time
# Grab a user
user = User.find(1)
# Now set an attribute that didn't exist before
user.expandos.foreground = '#FF0000'
# foreground is saved in Mongo
user.save

# Find any users with a red foreground color
users = User.expando_all(
  :conditions=>{:foreground=>'#FF0000'}
)
Skip expandos, use delegate
 class Post < ActiveRecord::Base
   expando_config do
     delegate :tags
   end
 end

 p = Post.find(1)
 p.tags = ['foo','bar']
 p.save

 # Find any Post with the tag "foo"
 Post.expando_all(:conditions=>{'tags'=>'foo'})
It’s a rails plugin
It’s on GitHub
(http://github.com/hayesdavis/active-expando)
Other issues
Where we’re going we
don’t need migrations
       (or do we?)
                     http://www.gordtep.com/files/2009/08/bttf2.jpg
Flexibility is great
   (until it bites you)
A general
word of
 caution
MongoDB is a moving
      target
So are the tools
There will be bugs




           http://nitishkrishna.files.wordpress.com/2009/07/2007_there_will_be_blood_013.jpg
So, be ready to upgrade
Questions?

More Related Content

What's hot

OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
Steven Francia
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
Kai Zhao
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
chriskite
 

What's hot (20)

OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
CouchDB introduction
CouchDB introductionCouchDB introduction
CouchDB introduction
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
 
Mongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case StudyMongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case Study
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
CouchDB
CouchDBCouchDB
CouchDB
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
 
Introduction to couchdb
Introduction to couchdbIntroduction to couchdb
Introduction to couchdb
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
 
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerMongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB and hadoop
MongoDB and hadoopMongoDB and hadoop
MongoDB and hadoop
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
 
CouchDB
CouchDBCouchDB
CouchDB
 
Couch db
Couch dbCouch db
Couch db
 
The NoSQL Way in Postgres
The NoSQL Way in PostgresThe NoSQL Way in Postgres
The NoSQL Way in Postgres
 

Viewers also liked

Digital business #2
Digital business #2Digital business #2
Digital business #2
finanzas_uca
 
clx_q4fy04_splmnt
clx_q4fy04_splmntclx_q4fy04_splmnt
clx_q4fy04_splmnt
finance48
 
Crystallized040910
Crystallized040910Crystallized040910
Crystallized040910
klee4vp
 
Trabalho De Matematica Completo
Trabalho De Matematica CompletoTrabalho De Matematica Completo
Trabalho De Matematica Completo
gueste1a09a
 
OFE draft 9 21 mitchell baker
OFE draft  9 21 mitchell bakerOFE draft  9 21 mitchell baker
OFE draft 9 21 mitchell baker
chefhja
 
Kitchenbathportfolio3
Kitchenbathportfolio3Kitchenbathportfolio3
Kitchenbathportfolio3
RaquelT
 
Thesis Update111909
Thesis Update111909Thesis Update111909
Thesis Update111909
klee4vp
 

Viewers also liked (20)

I festival de poesias mids
I festival de poesias   midsI festival de poesias   mids
I festival de poesias mids
 
PM processing 03 2015(eng)
PM processing 03 2015(eng)PM processing 03 2015(eng)
PM processing 03 2015(eng)
 
Tennesse.Teresa Bergera
Tennesse.Teresa BergeraTennesse.Teresa Bergera
Tennesse.Teresa Bergera
 
BNZ, hoe wordt je vrienden met Google presentation 13-05-2015
BNZ, hoe wordt je vrienden met Google  presentation 13-05-2015BNZ, hoe wordt je vrienden met Google  presentation 13-05-2015
BNZ, hoe wordt je vrienden met Google presentation 13-05-2015
 
Digital business #2
Digital business #2Digital business #2
Digital business #2
 
Leermeester Centraal Leermeesterdag NN 8-3-2011
Leermeester Centraal Leermeesterdag NN 8-3-2011Leermeester Centraal Leermeesterdag NN 8-3-2011
Leermeester Centraal Leermeesterdag NN 8-3-2011
 
clx_q4fy04_splmnt
clx_q4fy04_splmntclx_q4fy04_splmnt
clx_q4fy04_splmnt
 
Crystallized040910
Crystallized040910Crystallized040910
Crystallized040910
 
Trabalho De Matematica Completo
Trabalho De Matematica CompletoTrabalho De Matematica Completo
Trabalho De Matematica Completo
 
Allati Jo Kepek
Allati Jo KepekAllati Jo Kepek
Allati Jo Kepek
 
How To Stay Young
How To Stay YoungHow To Stay Young
How To Stay Young
 
PaaSで簡単Railsアプリを公開しよう!
PaaSで簡単Railsアプリを公開しよう!PaaSで簡単Railsアプリを公開しよう!
PaaSで簡単Railsアプリを公開しよう!
 
Code Qualität in agilen Teams - code.talks Hamburg 2015
Code Qualität in agilen Teams - code.talks Hamburg 2015Code Qualität in agilen Teams - code.talks Hamburg 2015
Code Qualität in agilen Teams - code.talks Hamburg 2015
 
OFE draft 9 21 mitchell baker
OFE draft  9 21 mitchell bakerOFE draft  9 21 mitchell baker
OFE draft 9 21 mitchell baker
 
S Pr Ookjes Rsg Lingecollege 2 2011
S Pr Ookjes Rsg Lingecollege 2 2011S Pr Ookjes Rsg Lingecollege 2 2011
S Pr Ookjes Rsg Lingecollege 2 2011
 
CALLED to Instruct Them in the Practice UofN Meeting Korea:
CALLED to Instruct Them in the Practice UofN Meeting Korea:CALLED to Instruct Them in the Practice UofN Meeting Korea:
CALLED to Instruct Them in the Practice UofN Meeting Korea:
 
Kitchenbathportfolio3
Kitchenbathportfolio3Kitchenbathportfolio3
Kitchenbathportfolio3
 
Thesis Update111909
Thesis Update111909Thesis Update111909
Thesis Update111909
 
King Case Profiel Annemarie Kingma
King Case Profiel Annemarie KingmaKing Case Profiel Annemarie Kingma
King Case Profiel Annemarie Kingma
 
Metrics in the Real World | Online and Offline Analytics Tracking
Metrics in the Real World | Online and Offline Analytics TrackingMetrics in the Real World | Online and Offline Analytics Tracking
Metrics in the Real World | Online and Offline Analytics Tracking
 

Similar to Using MongoDB and a Relational Database at MongoDB Day

Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010
Christian Heilmann
 
Microsoft Power Point Best Practices For Scaling Heavily Adopted And Concur...
Microsoft Power Point   Best Practices For Scaling Heavily Adopted And Concur...Microsoft Power Point   Best Practices For Scaling Heavily Adopted And Concur...
Microsoft Power Point Best Practices For Scaling Heavily Adopted And Concur...
Steve Feldman
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
guestebde
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right tools
Christian Heilmann
 

Similar to Using MongoDB and a Relational Database at MongoDB Day (20)

Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Yahoo is open to developers
Yahoo is open to developersYahoo is open to developers
Yahoo is open to developers
 
Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010Using Web Services with JavaScript - Fronttrends 2010
Using Web Services with JavaScript - Fronttrends 2010
 
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Microsoft Power Point Best Practices For Scaling Heavily Adopted And Concur...
Microsoft Power Point   Best Practices For Scaling Heavily Adopted And Concur...Microsoft Power Point   Best Practices For Scaling Heavily Adopted And Concur...
Microsoft Power Point Best Practices For Scaling Heavily Adopted And Concur...
 
Joomla Day Austin Part 4
Joomla Day Austin Part 4Joomla Day Austin Part 4
Joomla Day Austin Part 4
 
Use Web Skills To Build Mobile Apps
Use Web Skills To Build Mobile AppsUse Web Skills To Build Mobile Apps
Use Web Skills To Build Mobile Apps
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
The goodies of zope, pyramid, and plone (2)
The goodies of zope, pyramid, and plone (2)The goodies of zope, pyramid, and plone (2)
The goodies of zope, pyramid, and plone (2)
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
Building great mobile apps: Somethings you might want to know
Building great mobile apps: Somethings you might want to knowBuilding great mobile apps: Somethings you might want to know
Building great mobile apps: Somethings you might want to know
 
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right tools
 
Google App Engine for Java v0.0.2
Google App Engine for Java v0.0.2Google App Engine for Java v0.0.2
Google App Engine for Java v0.0.2
 
Writing native Linux desktop apps with JavaScript
Writing native Linux desktop apps with JavaScriptWriting native Linux desktop apps with JavaScript
Writing native Linux desktop apps with JavaScript
 
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
 
He stopped using for/while loops, you won't believe what happened next!
He stopped using for/while loops, you won't believe what happened next!He stopped using for/while loops, you won't believe what happened next!
He stopped using for/while loops, you won't believe what happened next!
 
Rails 101
Rails 101Rails 101
Rails 101
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Using MongoDB and a Relational Database at MongoDB Day