• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Using MongoDB and a Relational Database at MongoDB Day
 

Using MongoDB and a Relational Database at MongoDB Day

on

  • 24,398 views

Talk given at MongoDB Day in Austin about how to make MongoDB and a relational database work together in your application.

Talk given at MongoDB Day in Austin about how to make MongoDB and a relational database work together in your application.

Statistics

Views

Total Views
24,398
Views on SlideShare
8,554
Embed Views
15,844

Actions

Likes
8
Downloads
192
Comments
0

23 Embeds 15,844

http://nosql.mypopescu.com 13844
http://hayesdavis.net 1797
http://radhagumm.blogspot.com 85
http://www.slideshare.net 44
http://webcache.googleusercontent.com 22
http://translate.googleusercontent.com 19
http://radhagumm.blogspot.ru 7
http://radhagumm.blogspot.ca 5
http://static.slidesharecdn.com 4
http://radhagumm.blogspot.it 2
http://radhagumm.blogspot.in 2
http://radhagumm.blogspot.co.uk 2
http://getbyblock.com 1
https://www.google.com 1
http://radhagumm.blogspot.fi 1
http://www.linkedin.com 1
https://duckduckgo.com 1
http://radhagumm.blogspot.dk 1
http://radhagumm.blogspot.co.nz 1
http://safe.tumblr.com 1
http://webw-reader.appspot.com 1
http://74.6.238.254 1
http://radhagumm.blogspot.com.tr 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
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Using MongoDB and a Relational Database at MongoDB Day Using MongoDB and a Relational Database at MongoDB Day Presentation Transcript

    • 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?