SlideShare a Scribd company logo
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?
Ad

Recommended

PDF
Building Hybrid data cluster using PostgreSQL and MongoDB
Ashnikbiz
 
KEY
MongoDB, E-commerce and Transactions
Steven Francia
 
KEY
Optimize drupal using mongo db
Vladimir Ilic
 
PDF
NoSQL into E-Commerce: lessons learned
La FeWeb
 
PDF
Scaling up and accelerating Drupal 8 with NoSQL
OSInet
 
KEY
MongoDB and Ecommerce : A perfect combination
Steven Francia
 
PDF
Introduction to MongoDB
Justin Smestad
 
PPTX
MongoDB Aggregation Performance
MongoDB
 
KEY
OSCON 2012 MongoDB Tutorial
Steven Francia
 
KEY
MongoDB
Steven Francia
 
PPTX
Mongodb introduction and_internal(simple)
Kai Zhao
 
KEY
CouchDB introduction
Sander van de Graaf
 
PPTX
Intro To Mongo Db
chriskite
 
KEY
Mongodb and Totsy - E-commerce Case Study
Mitch Pirtle
 
PDF
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
PDF
Mongo DB
Edureka!
 
PPT
CouchDB
Niklas Gustavsson
 
PDF
MongoDB WiredTiger Internals
Norberto Leite
 
PDF
Introduction to couchdb
iammutex
 
KEY
Practical Ruby Projects With Mongo Db
Alex Sharp
 
PDF
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
Valeri Karpov
 
PPT
MongoDB Pros and Cons
johnrjenson
 
PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
KEY
MongoDB and hadoop
Steven Francia
 
PDF
MongodB Internals
Norberto Leite
 
PDF
CouchDB
codebits
 
PPTX
Couch db
amini gazar
 
PPT
The NoSQL Way in Postgres
EDB
 
PPTX
I festival de poesias mids
Silviene Florentino
 
PDF
PM processing 03 2015(eng)
Vadim Andreev
 

More Related Content

What's hot (20)

KEY
OSCON 2012 MongoDB Tutorial
Steven Francia
 
KEY
MongoDB
Steven Francia
 
PPTX
Mongodb introduction and_internal(simple)
Kai Zhao
 
KEY
CouchDB introduction
Sander van de Graaf
 
PPTX
Intro To Mongo Db
chriskite
 
KEY
Mongodb and Totsy - E-commerce Case Study
Mitch Pirtle
 
PDF
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
PDF
Mongo DB
Edureka!
 
PPT
CouchDB
Niklas Gustavsson
 
PDF
MongoDB WiredTiger Internals
Norberto Leite
 
PDF
Introduction to couchdb
iammutex
 
KEY
Practical Ruby Projects With Mongo Db
Alex Sharp
 
PDF
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
Valeri Karpov
 
PPT
MongoDB Pros and Cons
johnrjenson
 
PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
KEY
MongoDB and hadoop
Steven Francia
 
PDF
MongodB Internals
Norberto Leite
 
PDF
CouchDB
codebits
 
PPTX
Couch db
amini gazar
 
PPT
The NoSQL Way in Postgres
EDB
 
OSCON 2012 MongoDB Tutorial
Steven Francia
 
Mongodb introduction and_internal(simple)
Kai Zhao
 
CouchDB introduction
Sander van de Graaf
 
Intro To Mongo Db
chriskite
 
Mongodb and Totsy - E-commerce Case Study
Mitch Pirtle
 
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
Mongo DB
Edureka!
 
MongoDB WiredTiger Internals
Norberto Leite
 
Introduction to couchdb
iammutex
 
Practical Ruby Projects With Mongo Db
Alex Sharp
 
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
Valeri Karpov
 
MongoDB Pros and Cons
johnrjenson
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB and hadoop
Steven Francia
 
MongodB Internals
Norberto Leite
 
CouchDB
codebits
 
Couch db
amini gazar
 
The NoSQL Way in Postgres
EDB
 

Viewers also liked (20)

PPTX
I festival de poesias mids
Silviene Florentino
 
PDF
PM processing 03 2015(eng)
Vadim Andreev
 
PPTX
Tennesse.Teresa Bergera
mariavigarces
 
PPTX
BNZ, hoe wordt je vrienden met Google presentation 13-05-2015
John Meijering ✔
 
PDF
Digital business #2
finanzas_uca
 
PPTX
Leermeester Centraal Leermeesterdag NN 8-3-2011
Johan Lapidaire
 
PDF
clx_q4fy04_splmnt
finance48
 
PDF
Crystallized040910
klee4vp
 
ODT
Trabalho De Matematica Completo
gueste1a09a
 
PPS
Allati Jo Kepek
guestba8001
 
PPTX
How To Stay Young
Rajesh Goyal
 
PDF
PaaSで簡単Railsアプリを公開しよう!
Yoshitake Takata
 
PDF
Code Qualität in agilen Teams - code.talks Hamburg 2015
Frank Sons
 
PDF
OFE draft 9 21 mitchell baker
chefhja
 
PPTX
S Pr Ookjes Rsg Lingecollege 2 2011
Johan Lapidaire
 
PPT
CALLED to Instruct Them in the Practice UofN Meeting Korea:
Allan Carrington
 
PPT
Kitchenbathportfolio3
RaquelT
 
PPTX
Thesis Update111909
klee4vp
 
PPT
King Case Profiel Annemarie Kingma
Annemarie Kingma
 
PPTX
Metrics in the Real World | Online and Offline Analytics Tracking
Caitlin Jeansonne
 
I festival de poesias mids
Silviene Florentino
 
PM processing 03 2015(eng)
Vadim Andreev
 
Tennesse.Teresa Bergera
mariavigarces
 
BNZ, hoe wordt je vrienden met Google presentation 13-05-2015
John Meijering ✔
 
Digital business #2
finanzas_uca
 
Leermeester Centraal Leermeesterdag NN 8-3-2011
Johan Lapidaire
 
clx_q4fy04_splmnt
finance48
 
Crystallized040910
klee4vp
 
Trabalho De Matematica Completo
gueste1a09a
 
Allati Jo Kepek
guestba8001
 
How To Stay Young
Rajesh Goyal
 
PaaSで簡単Railsアプリを公開しよう!
Yoshitake Takata
 
Code Qualität in agilen Teams - code.talks Hamburg 2015
Frank Sons
 
OFE draft 9 21 mitchell baker
chefhja
 
S Pr Ookjes Rsg Lingecollege 2 2011
Johan Lapidaire
 
CALLED to Instruct Them in the Practice UofN Meeting Korea:
Allan Carrington
 
Kitchenbathportfolio3
RaquelT
 
Thesis Update111909
klee4vp
 
King Case Profiel Annemarie Kingma
Annemarie Kingma
 
Metrics in the Real World | Online and Offline Analytics Tracking
Caitlin Jeansonne
 
Ad

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

ODP
Introduce Django
Chui-Wen Chiu
 
PDF
Yahoo is open to developers
Christian Heilmann
 
PDF
Using Web Services with JavaScript - Fronttrends 2010
Christian Heilmann
 
PDF
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Matt Raible
 
PPTX
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Deepu S Nath
 
PDF
Java and AI with LangChain4j: Jakarta EE and AI
Edward Burns
 
PDF
Adobe Photoshop 2025 Free crack Download
toomjerry493
 
PDF
Microsoft Power Point Best Practices For Scaling Heavily Adopted And Concur...
Steve Feldman
 
PPT
Joomla Day Austin Part 4
Kyle Ledbetter
 
PDF
Use Web Skills To Build Mobile Apps
Nathan Smith
 
PPT
Demystifying Maven
Mike Desjardins
 
PDF
The goodies of zope, pyramid, and plone (2)
Dylan Jay
 
PDF
10 Ways To Improve Your Code( Neal Ford)
guestebde
 
PDF
Building great mobile apps: Somethings you might want to know
shwetank
 
PDF
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
Marco Cedaro
 
PDF
JavaScript Miller Columns
Jonathan Fine
 
PDF
Building with JavaScript - write less by using the right tools
Christian Heilmann
 
PDF
Google App Engine for Java v0.0.2
Matthew McCullough
 
PDF
Writing native Linux desktop apps with JavaScript
Igalia
 
PDF
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
Marco Cedaro
 
Introduce Django
Chui-Wen Chiu
 
Yahoo is open to developers
Christian Heilmann
 
Using Web Services with JavaScript - Fronttrends 2010
Christian Heilmann
 
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Matt Raible
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Deepu S Nath
 
Java and AI with LangChain4j: Jakarta EE and AI
Edward Burns
 
Adobe Photoshop 2025 Free crack Download
toomjerry493
 
Microsoft Power Point Best Practices For Scaling Heavily Adopted And Concur...
Steve Feldman
 
Joomla Day Austin Part 4
Kyle Ledbetter
 
Use Web Skills To Build Mobile Apps
Nathan Smith
 
Demystifying Maven
Mike Desjardins
 
The goodies of zope, pyramid, and plone (2)
Dylan Jay
 
10 Ways To Improve Your Code( Neal Ford)
guestebde
 
Building great mobile apps: Somethings you might want to know
shwetank
 
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
Marco Cedaro
 
JavaScript Miller Columns
Jonathan Fine
 
Building with JavaScript - write less by using the right tools
Christian Heilmann
 
Google App Engine for Java v0.0.2
Matthew McCullough
 
Writing native Linux desktop apps with JavaScript
Igalia
 
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
Marco Cedaro
 
Ad

Recently uploaded (20)

PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PDF
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
PDF
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
PDF
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
PDF
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
PDF
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
PDF
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PDF
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
PDF
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
PPTX
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
The Growing Value and Application of FME & GenAI
Safe Software
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 

Using MongoDB and a Relational Database at MongoDB Day