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

20
with Mongoid * MongoDB + RoR

Upload: fundacja-polak-20

Post on 25-May-2015

1.475 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

with Mongoid

*MongoDB + RoR

Page 2: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*Agenda

*NoSQL

*What is MongoDB?

*Comparison – MongoDB vs. RDBMS

*What is Mongoid?

*Live MongoDB + Rails examples

*Pros and cons

*Summary

Page 3: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*My experience

*Been working with Mongoid for a few months

*MongoDB 1.6

*Mongoid 2.0.0.beta.20

*Not yet on production

Page 4: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*NoSQL movement

Page 5: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*So what exactly is MongoDB?

*Document oriented Database

*Supports indexes

*Rich querying

*Auto-sharding

*GridFS

*BSON format

Page 6: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*MongoDB vs. SQL

Document Documentreference

Documentreference

Page 7: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*MongoDB vs. SQL

Document

Embedded document

Embedded document

Documentreference

Documentreference

Page 8: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*MongoDB vs. SQL

Document

Embedded document

Embedded document

Documentreference

Documentreference

Page 9: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*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…

Page 10: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*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

Page 11: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*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

Page 12: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*How to use ?

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

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

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

Page 13: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*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]

Page 14: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*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!)

Page 15: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*Examples of

Roflcopter.pl

Page 16: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*Summary

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

Page 17: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*Summary

But…

Page 18: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*Summary

…don’t wait and try it yourself!

Page 19: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*Summary

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

Page 20: Grzegorz Witek - MongoDB + RoR, Mongoid (PRUG 1.0)

*Kolejne spotkanie

*28 kwietnia – 19:00

*Prezentacje?

[email protected]

http://prug.pl