• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Mongoid

  • 2,873 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,873
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
30
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Going NoSQL with Mongoid
  • 2. What do I want to share?
    What Mongoid is, and why you should use it.
    Some very brief examples of it’s capabilities
    A setup that will allow you to follow bdd/tdd, while using Mongoid (i.e. some of the gems you take for granted don’t work without ActiveRecord)
  • 3. What is MongoDB?
    MongoDB is one of several possible ‘NoSQL’ Databases
    Other Examples might be: CouchDB, Tokyo Cabinet, Voldemort, …
    MongoDB falls into the ‘Document Database’ sub category of NoSQL
  • 4. Why MongoDB over X?
    Ease of installation
    Works on Mac, Windows, Linux
    Easy to develop with (e.g. no migrations)
    Excellent Documentation (both MongoDB and Mongoid)
    I’ve only used it on smaller projects so limitations that might appear at scale are not of concern to me.
  • 5. MongoDB Features
    Full Index Support
    Replication and Scalability
    Auto-Sharding
    Querying
    Fast In-Place Updates
    Map/Reduce
  • 6. Installing MongoDB
    Install the latest production version from mongodb.org
    - Mongoid currently wants MongoDB 1.6.0 or greater
    - (Debian/Ubuntu)Turn off listening on 0.0.0.0 or enable authentication
  • 7. Mongoid vs. MongoMapper
    Mongoid is uses ActiveModel – MM is Rails2 focused and used the validatable gem
    Mongoid provides excellent support for embedded documents
    Mongoid has better performance with large datasets and large documents
    Mongoid has better documentation
  • 8. Mongoid Features
    Plays nicely with Rails3 (Takes advantage of ActiveModel)
    Excellent chainable query interface
    Quite a few existing gems have versions that support Mongoid
    E.g. Delayed::Job and Devise can both use MongoDB through Mongoid
  • 9. Mongoid Features (continued)
    Mongoid supports Master/Slave replication clusters
    Writes to masters, round robin reads to slaves
    Great support for embedded documents
    Person.not_in(:status => ["Divorced", "Single"])
  • 10. Mongoid Associations
    embeds_one, embeds_many and embedded_in
    references_one, references_many, and referenced_in
    references_many :transactions vsreferences_many:transactions, :stored_as => :array
    (http://mongoid.org/docs/associations/)
  • 11. Querying using Mongoid
    Person.all(:conditions => { :first_name => "Syd" })
    Person.find(:all, :conditions => { :first_name => "Syd" })
    Person.not_in(:status => ["Divorced", "Single"]).only(:first_name, :last_name).limit(20)
    (http://mongoid.org/docs/querying/)
  • 12. Useful gems
    gem 'machinist_mongo', :require => 'machinist/mongoid', :git => 'http://github.com/nmerouze/machinist_mongo.git', :branch => 'machinist2’
    gem 'delayed_job', :git => 'http://github.com/collectiveidea/delayed_job.git', :branch => 'rails3-mailer'
    gem 'delayed_job_mongoid', '>= 1.0.0.rc’
    gem 'mongoid-rspec’ # http://github.com/evansagge/mongoid-rspec
  • 13. Useful gems (continued)
    https://github.com/adacosta/mongoid_rails_migrations
    https://github.com/azisaka/mongoid_state_machine
  • 14. New application
    rails new app_name –O –J –T –mhttp://bit.ly/bV9gUn
  • 15. RSpec
    RSpec.configuredo |config|
    config.before:all do
    Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
    end
    end
    http://adventuresincoding.com/2010/07/how-to-configure-cucumber-and-rspec-to-work-with-mongoid/
  • 16. Cucumber
    Before do |scenario|
    Mongoid.master.collections.select{|c| c.name !~ /system/ }.each(&:drop)
    end
    http://adventuresincoding.com/2010/07/how-to-configure-cucumber-and-rspec-to-work-with-mongoid/
  • 17. Delayed Job
    # config/initializers/delayed_job_config.rb
    Delayed::Worker.backend = :mongoid

  • 18. Resources
    MongoDB - http://www.mongodb.org
    Mongoid – http://www.mongoid.org
    Mongoid Source - http://github.com/mongoid/mongoid
    My Rails Template - http://bit.ly/bV9gUn (There are probably more generic/complete templates out there)
  • 19. My Details
    Luke Chadwick
    Blog: http://core.vertislabs.org
    Twitter: vertis
    Email: luke.a.chadwick@gmail.com