grzegorz witek - mongodb + ror, mongoid (prug 1.0)

Post on 25-May-2015

1.475 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

with Mongoid

*MongoDB + RoR

*Agenda

*NoSQL

*What is MongoDB?

*Comparison – MongoDB vs. RDBMS

*What is Mongoid?

*Live MongoDB + Rails examples

*Pros and cons

*Summary

*My experience

*Been working with Mongoid for a few months

*MongoDB 1.6

*Mongoid 2.0.0.beta.20

*Not yet on production

*NoSQL movement

*So what exactly is MongoDB?

*Document oriented Database

*Supports indexes

*Rich querying

*Auto-sharding

*GridFS

*BSON format

*MongoDB vs. SQL

Document Documentreference

Documentreference

*MongoDB vs. SQL

Document

Embedded document

Embedded document

Documentreference

Documentreference

*MongoDB vs. SQL

Document

Embedded document

Embedded document

Documentreference

Documentreference

*What is ?

*Think of ActiveRecord for MongoDB

*Mapping Ruby objects to MongoDB documents and embedded documents

*Supports Rails3

*Named scopes, rich criteria API

*Also some problems…

*How to use ?

class Building include Mongoid::Document

include Mongoid::Timestamps

embeds_many :floors

field :name

field :occupied, :type => Boolean, :default => false

field :area, :type => Integer

end

*How to use ?

class Level include Mongoid::Document

embedded_in :building, :inverse_of => :levels

embeds_many :rooms

field :type

validate :type, :presence => true, :uniqueness => {:scope => :city}

end

*How to use ?

Building.first(:conditions => {:name.in => [“Dom”,”Stodoła”]})

Building.levels.where(:type => “poddasze”)

Building.find(:all, :conditions => {:area.gt => 100})

*How to use ?

Callbacks:

after_save, before_save, before_validation, after_create, etc.

Inheritance:

class House < Building

end

house = House.new; house._type # => “house”

Building.all # [house]

*Pros and cons of

Pros Cons

• Gives the power of MongoDB

o collectionso Good for heavy-write

applicationso Auto-sharding• Very similar to

ActiveRecord• Dynamic development

• Many bugs• Documentation for 2.0 is

not complete• Not all gems are

compatible• Slow references

(embedding over references!)

*Examples of

Roflcopter.pl

*Summary

Summary in a few months (when our app goes production)

*Summary

But…

*Summary

…don’t wait and try it yourself!

*Summary

http://mongodb.orghttp://mongoid.org

*Kolejne spotkanie

*28 kwietnia – 19:00

*Prezentacje?

talks@prug.pl

http://prug.pl

top related